Random numbers What does it mean for a number to be random?

Slides:



Advertisements
Similar presentations
Numerical Methods or Two Recipes for Pi CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
Advertisements

Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Exercise 4 1. Write a program that simulates coin tossing. For each toss of the coin the program should print Heads or Tails. Let the program toss the.
Section 7A: Fundamentals of Probability Section Objectives Define outcomes and event Construct a probability distribution Define subjective and empirical.
Mathematics in Today's World
Modeling and Simulation Monte carlo simulation 1 Arwa Ibrahim Ahmed Princess Nora University.
Dice Games & Probabilities. Thermo & Stat Mech - Spring 2006 Class 16 Dice Games l One die has 6 faces. So, the probabilities associated with a dice game.
VK Dice By: Kenny Gutierrez, Vyvy Pham Mentors: Sarah Eichhorn, Robert Campbell.
Monopoly Game Example Mutually Exclusive.
Markov Chain Andrew Wang. Yum Probability
Pricing an Option Monte Carlo Simulation. We will explore a technique, called Monte Carlo simulation, to numerically derive the price of an option or.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
Chapter 11: understanding randomness (Simulations)
Refreshing Your Skills for Chapter 10.  If you flip a coin, the probability that it lands with heads up is 1/2.  If you roll a standard die, the probability.
Copyright © 2010 Pearson Education, Inc. Unit 3: Gathering Data Chapter 11 Understanding Randomness.
CSCE 2100: Computing Foundations 1 Probability Theory Tamara Schneider Summer 2013.
MOM! Phineas and Ferb are … Aims:
STAT115 STAT225 BIST512 BIO298 - Intro to Computational Biology Python Tutorial II Monty Python, Game of Life and Sequence Alignment Feb 1, 2011 Daniel.
CS320n –Visual Programming More LabVIEW Control Structures.
Slide 7- 1 Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
DiceRoller DiceRoller (object class) and DiceRollerViewer client class: Write a DiceRoller class (similar to Yahtzee) to: Allow the person to initially.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
Chapter 9 Review. 1. Give the probability of each outcome.
If..else Use random numbers to compute an approximation of pi Simulation of a special game of darts Randomly place darts on the board pi can be computed.
CALCULATE THE PROBABILITY OF AN EVENT. 1.ANSWER THIS QUESTION: IS THE EVENT POSSIBLE? STOP: DON’T CONTINUE. THE PROBABILITY OF THE EVENT IS O GO TO NUMBER.
CS 121 Today Fractals and Turtles! The Koch Curve how random…
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
Expected Value.
M ONTE C ARLO SIMULATION Modeling and Simulation CS
Computer simulation Sep. 9, QUIZ 2 Determine whether the following experiments have discrete or continuous out comes A fair die is tossed and the.
CHAPTER 5 Simulation Modeling. Introduction In many situations a modeler is unable to construct an analytic (symbolic) model adequately explaining the.
Bernoulli Trials, Geometric and Binomial Probability models.
CSci 162 Lecture 7 Martin van Bommel. Random Numbers Until now, all programs have behaved deterministically - completely predictable and repeatable based.
From Wikipedia: “Parametric statistics is a branch of statistics that assumes (that) data come from a type of probability distribution and makes inferences.
MAT 4830 Mathematical Modeling 04 Monte Carlo Integrations
Chapter 6—Objects and Classes The Art and Science of An Introduction to Computer Science ERIC S. ROBERTS Java Objects and Classes C H A P T E R 6 To beautify.
COMPUTERS SIMULATION IN MATHEMATICS EDUCATION Dr. Ronit Hoffmann Kibbutzim College of Education, Israel.
PROBABILITY DISTRIBUTIONS DISCRETE RANDOM VARIABLES OUTCOMES & EVENTS Mrs. Aldous & Mr. Thauvette IB DP SL Mathematics.
Counting and Probability. Imagine tossing two coins and observing whether 0, 1, or 2 heads are obtained. Below are the results after 50 tosses Tossing.
Random Variables and Probability Distributions. Definition A random variable is a real-valued function whose domain is the sample space for some experiment.
CS 121 Today Fractals and Turtles! The Koch Curve how random…
Adding Probabilities 12-5
9.8 Probability Basic Concepts
Computer Simulation Henry C. Co Technology and Operations Management,
Monte Carlo Methods Some example applications in C++
Approximate computations
Chapter 6 6.1/6.2 Probability Probability is the branch of mathematics that describes the pattern of chance outcomes.
Monte Carlo simulation
Modelling and Simulating Social Systems with MATLAB
Intro CS – Probability and Random Numbers
Simulation Department of Industrial Engineering Anadolu University
Section 5.1 Basic Ideas.
LOOPS.
Approximate computations
Random numbers Taken from notes by Dr. Neil Moore
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
Random numbers What does it mean for a number to be random?
Various Random Number Generators and the Applications
Probability 14.1 Experimental Probability 14.2 Principles of Counting
Honors Statistics From Randomness to Probability
And and or…and RANDOMNESS
Chapter 11: Further Topics in Algebra
Lecture 2 Binomial and Poisson Probability Distributions
Standard Equation of a Circle Definition of a Circle
Statistics and Probability-Part 5
CS100A Lecture 21 Previous Lecture This Lecture
IST256 : Applications Programming for Information Systems
Lecture 9 Randomized Algorithms
Random numbers What does it mean for a number to be random?
Standard Equation of a Circle Definition of a Circle
Presentation transcript:

Random numbers What does it mean for a number to be random? A number that is drawn from a set of possible values, each of which is equally probable Many practical uses: Computer games Simulation of natural phenomena Cryptography Art, Music Etc… any problem where you want to produce an unpredictable result! Random Numbers What does it mean to have a random number? For example, if you want a random number between 1 and 6 (say like when rolling a die) it means each number comes up with probability 1/6. This does not mean that you will get the numbers 1-6 every 6 times you roll the die. It means that over the long run each of the numbers 1-6 will turn up 1/6 of the time. But you might have three 2’s in a row.

The random module Thankfully, you don't have to implement your own RNG import random from random import *

Some random functions… choice(myList) chooses 1 element from the sequence myList choice(['Harris', 'McDonnell', 'Larison']) How would you get a random int from 0 to 9 inclusive? randint(low,hi) chooses a random int from low to hi, inclusive

Throw a coin n times … from random import * def flipCoins(n = 20): mapping = ['H', 'T'] flipList = [ mapping[randint(0,1)] for flip in range(n) ] print(''.join(flipList))

This will do the same… from random import * def flipCoins(n = 20): flipList = [ choice([‘H’, ‘T’]) for flip in range(n) ] print(''.join(flipList))

Monte Carlo Methods Any method which solves a problem by generating suitable random numbers, and observing the fraction of numbers obeying some property (or properties) The method is useful for obtaining numerical solutions to problems which are too complicated to solve analytically. http://mathworld.wolfram.com/MonteCarloMethod.html

Monte Carlo in action How many doubles will you get in n rolls of 2 dice? the input n is the total number of rolls def countDoubles(n): """ inputs a # of dice rolls outputs the # of doubles """ if n == 0: return 0 # zero rolls, zero doubles… else: d1 = choice([1,2,3,4,5,6]) d2 = choice(range(1,7)) if d1 != d2: return countDoubles(n-1) # don't count it return 1 + countDoubles(n-1) # COUNT IT! one roll where is the doubles check?

Write the same function with Monte Carlo in action Write the same function with a list comprehension def countDoubles(n): """ inputs a # of dice rolls outputs the # of doubles """ return sum([choice(range(6)) == choice(range(6)) \ for x in range(n)]) Run countDoubles(2) where is the doubles check?

One final example… Suppose you wanted to estimate pi Generate two random numbers between -1 and 1. denoted (x,y) Compute the distance of (x,y) from (0,0) Depending on distance, point is either inside or outside of a circle centered at (0,0) with a radius of 1. Illustration…

Quiz Design a strategy for estimating pi using random numbers ("dart throws") and this diagram ("dartboard"): Name(s): (1,1) What does this return? 1) Here is a dart-throwing function: def throw(): return [ random.uniform(-1,1), random.uniform(-1,1) ] 2) Here is a dart-testing function: What does this return? (-1,-1) def test(x,y): return (x**2 + y**2) < 1.0 3) What strategy could use the functions in (1) and (2) to estimate pi? 4) Write a function to implement your strategy: