Grade by Grade
A. Counting and Probability · Probability

Designing and Using Simulations

A1.4About 70 minutes
Learning goals
  • I can design a simulation that models a real situation, using coins, dice, cards, random digits or technology.
  • I can run a simulation, record results and use them to estimate a probability.
  • I can compare a simulation's estimate with a theoretical probability when one can be found.
  • I can explain the strengths and limitations of a simulation, including how the number of trials affects the estimate.

Words to know

simulation
An experiment that imitates a real situation using a model with the same probabilities, such as dice standing in for random events.
trial
One complete run of the simulation, which produces one result to record.
random number generator
A device or program that produces numbers with no predictable pattern, each value equally likely (for example RANDBETWEEN in a spreadsheet).
random digits
A sequence of the digits 0 to 9 in which each digit is equally likely and independent of the others.
Monte Carlo method
Estimating a probability or quantity by running a large number of random simulated trials on a computer.

Why simulate?

Some probabilities are hard or impossible to calculate, and some experiments are too slow, costly or dangerous to repeat for real. A simulation replaces the real situation with a random model that has the same probabilities, then repeats it many times.

Engineers simulate traffic before building an intersection. Epidemiologists simulate the spread of a flu season. Hockey analysts simulate the rest of a season thousands of times to estimate a team's playoff chances. Computers make it practical to run millions of trials; this is called the Monte Carlo method.

By the law of large numbers (lesson 5), the more trials you run, the better the estimate tends to be.

1. Modellist outcomes andtheir probabilities2. Devicematch outcomes tocoins, dice, digits3. Trialdefine one trial andwhat to record4. Repeatrun many trials(hundreds if possible)5. Estimaterelative frequency= experimental P6. Interpret: compare with theory if possible, and state limitations.
The steps of a simulation. The model and the device must have the same probabilities as the real situation, or the results mean nothing.

Choosing a random device

  • Coin: two equally likely outcomes (probability 1/2).
  • Die: six equally likely outcomes; use 1 to 3 versus 4 to 6 for 1/2, or ignore some faces and re-roll.
  • Cards: draw and replace to keep probabilities fixed; draw without replacement to model dependent events.
  • Random digits 0 to 9: each digit has probability 0.1, each pair 00 to 99 has probability 0.01. Assign digits to match the probability: for 70%, use 0 to 6 for "yes" and 7 to 9 for "no".
  • Technology: spreadsheets, graphing calculators and programming languages generate random numbers quickly.
Spreadsheet formulas (Google Sheets, Excel or LibreOffice Calc):
=RANDBETWEEN(1,6) a random whole number from 1 to 6 (one die roll)
=RAND() a random decimal from 0 up to (not including) 1
=IF(RAND()<0.7,1,0) 1 with probability 0.7, otherwise 0
=COUNTIF(A1:A1000,2)/1000 the relative frequency of 2s in cells A1 to A1000
Copy a formula down 1000 rows to run 1000 trials. Press F9 (or edit any cell) to rerun.

Spreadsheet tools for simulations. RAND() < 0.7 is true 70% of the time, so it models any event with probability 0.7.

Worked example

Example 1: Random digits

A basketball player makes 70% of her free throws. Use random digits to estimate the probability she makes both shots on a two-shot trip to the line. Use the 40 digits 74852 60574 79380 92752 53093 18561 00831 67162.

  1. Model: each shot is made with probability 0.7, independently.
  2. Device: digits 0 to 6 = make (7 of 10 digits = 0.7), 7 to 9 = miss.
  3. Trial: one pair of digits = two shots. Record "both" if both digits are 0 to 6.
  4. Run: split into 20 pairs: 74, 85, 26, 05, 74, 79, 38, 09, 27, 52, 53, 09, 31, 85, 61, 00, 83, 16, 71, 62. Both made: 26, 05, 52, 53, 31, 61, 00, 16, 62 = 9 trials.
  5. Estimate: 9/20 = 0.45.
  6. Compare: the theoretical value is 0.7 × 0.7 = 0.49 (independent events, lesson 10). With only 20 trials, 0.45 is reasonably close.

Simulation estimate: P(both) ≈ 0.45; theoretical: 0.49. More trials would usually give a closer estimate.

Digits 0–6 = make (70%), 7–9 = miss (30%). Each pair of digits = one trip to the line.74no85no26both05both74no79no38no09no27no52both53both09no31both85no61both00both83no16both71no62bothShaded pairs: both digits are 0–6 (both shots made). 9 of 20 trials, so P ≈ 9/20 = 0.45.
Each pair of random digits simulates two free throws. The shaded pairs are trials where both shots were made.
Worked example

Example 2: Collecting all the prizes

A cereal company puts one of 6 different hockey cards in each box, each equally likely. Design a simulation to estimate how many boxes you must buy to collect all 6 cards, and estimate P(you need more than 20 boxes).

  1. Model: each box gives card 1 to 6 with probability 1/6 each, independently.
  2. Device: one die roll = one box.
  3. Trial: roll until every face 1 to 6 has appeared at least once. Record the number of rolls.
  4. Run: ten trials by hand gave 7, 20, 12, 8, 16, 14, 14, 8, 33, 8 rolls (mean 14.0). A spreadsheet ran 1000 trials; the histogram below shows the results. Their mean was 14.8 boxes, and 166 of the 1000 trials needed more than 20 boxes.
  5. Estimate: P(more than 20 boxes) ≈ 166/1000 ≈ 0.17.
  6. Interpret: on average you need about 15 boxes, but about 1 buyer in 6 needs more than 20. (A theoretical calculation, beyond this course, gives an average of 14.7 boxes, very close to the simulation.)

Average about 15 boxes; P(more than 20) ≈ 0.17. Ten hand trials give a rough idea; 1000 computer trials give a much more reliable estimate.

1002003004006–1026011–1537916–2019521–2510026–304231+24number of trialsboxes needed to collect all 6 prizes (1000 simulated trials)
Results of 1000 simulated trials of collecting all 6 cards. Most trials need 6 to 20 boxes, but the long tail on the right shows some unlucky collectors needing more than 30.
Worked example

Example 3: Guessing on a quiz

A student guesses every answer on a 5-question multiple-choice quiz with 4 choices each. Design a simulation with a spreadsheet to estimate P(at least 3 correct). Then compare with the theoretical value 106/1024.

  1. Model: each guess is correct with probability 1/4, independently.
  2. Device: in each of 5 columns use =IF(RANDBETWEEN(1,4)=1,1,0), which gives 1 (correct) one time in 4.
  3. Trial: one row of 5 cells = one quiz. In a sixth column, add the row and test whether the total is at least 3.
  4. Run: copy the row down 1000 times. One run gave 104 quizzes with at least 3 correct.
  5. Estimate: 104/1000 = 0.104. Theoretical: 106/1024 ≈ 0.1035. Very close.

P(at least 3 correct) ≈ 0.10. Guessing passes this quiz only about 1 time in 10. (You will calculate the exact value with the binomial distribution in the unit Discrete Probability Distributions.)

A simulation is only as good as its model

  • The device's probabilities must match the real situation (a coin is a bad model for a 70% shooter).
  • Trials should be independent if the real events are (re-roll and replace).
  • Run many trials: 20 gives a rough idea, 1000 a good estimate.
  • State the assumptions. Real free throws may not be independent (a player may get nervous after a miss), so the simulation answers "what if they were independent?"
Just for fun

The Monte Carlo method is named after the famous casino in Monaco. Stanislaw Ulam and John von Neumann developed it at Los Alamos in the 1940s, and their colleague Nicholas Metropolis suggested the name: a method built on chance, and a nod to Ulam's uncle, who loved to gamble at Monte Carlo.

Hands-on activity

Simulate the prize hunt

You need: one die, paper and a pencil. Optional: a spreadsheet program or free online spreadsheet.

  1. Read Example 2. Do 10 trials of the prize hunt yourself: roll the die until you have seen all six faces, ticking each face off as it appears. Record the number of rolls for each trial.
  2. Find your mean number of rolls and the proportion of your trials that needed more than 20 rolls.
  3. Combine your results with the 10 hand trials in Example 2 to make 20 trials. Recalculate.
  4. Change the problem: what if there were only 4 cards? Simulate using a die and re-rolling any 5 or 6. Do 10 trials.
  5. (Optional) In a spreadsheet, put =RANDBETWEEN(1,6) in cells A1 to A100 and see how many cells it takes to see all six values. Press F9 to rerun.

What to look for: your mean for 6 cards should usually be somewhere from about 10 to 20; small samples vary a lot. For 4 cards the mean should be smaller, around 8 (the theoretical average is 4(1 + 1/2 + 1/3 + 1/4) ≈ 8.3).

Your turn

1

Describe how to use a coin to simulate whether each of 4 babies born in a hospital is a boy or a girl, assuming each is equally likely.

2

A weather forecast gives a 30% chance of snow on each of the next 3 days. Assign random digits to simulate one day.

3

Use the digits 2 8 5 | 0 7 9 | 3 3 1 | 6 4 8 (four trials of 3 days each, using the assignment above) to estimate P(snow on at least one of the 3 days).

4

Why must a simulation use many trials?

5

How could you simulate an event with probability 1/3 using a die?

6

Write a spreadsheet formula that returns 1 with probability 0.15 and 0 otherwise.

7

A simulation of a 70% free-throw shooter used a coin (heads = make). What is wrong?

More practice: warm-up

1

What does one trial of a simulation produce?

2

Which digits would you assign to an event with probability 0.4?

3

How would you simulate drawing a card with replacement?

4

What does =RANDBETWEEN(1,6) model?

5

A simulation gives 37 successes in 200 trials. Experimental probability?

More practice: on your own

1

A goalie stops 90% of shots. Design a random-digit simulation to estimate P(she stops all of the next 5 shots).

2

A multiple-choice test has 10 questions with 5 choices each. Design a spreadsheet simulation to estimate P(a guesser gets at least 5 right).

3

Two-digit random numbers 00 to 99 are used to simulate an event with probability 0.37. Which numbers would you use?

4

In a simulation of 50 trials of a best-of-three series (each game 60% to win), the team won 34 series. Estimate P(win series) and compare with the theoretical value 0.648.

5

Give two reasons a team might use a computer simulation instead of a physical one with dice.

Challenge

1

A family plans to have children until they have a girl, with a maximum of 4 children. Assuming each child is equally likely to be a girl or a boy, design a coin simulation for the number of children. Then find the theoretical probability distribution of the number of children.

2

Explain how to use simulation to estimate the probability that, in a class of 25 students, at least two share a birthday. (Ignore February 29.)

3

A simulation is run 4 times, with 100 trials each, giving estimates 0.31, 0.24, 0.29 and 0.28. What single estimate would you report, and why might the four values differ?

Check your understanding

Quiz

1.

Which device correctly simulates an event with probability 0.25?

2.

Random digits are used to simulate a 40% chance of rain. Which assignment is correct?

3.

A simulation estimates a probability as 0.32 using 25 trials. What is the best way to get a more reliable estimate?

4.

What does =IF(RAND()<0.6,1,0) produce?

5.

A simulation of a 75% free-throw shooter assumes shots are independent. Which is a limitation of this model?

6.

A trial in a simulation is:

For parents and teachers

Big idea (A1.4): a simulation is an experiment with a random model that has the same probabilities as the real situation. Running many trials gives an experimental probability; with enough trials it tends to approach the theoretical probability.

How to help: Do the prize hunt with a die together; it is quick and surprisingly fun. If you have a spreadsheet program, help your teen enter =RANDBETWEEN(1,6) and copy it down 1000 rows; pressing F9 reruns everything.

Common difficulties:

  • Choosing a device with the wrong probabilities (a coin for a 70% event).
  • Not defining clearly what one trial is and what to record.
  • Running too few trials and trusting the result.
  • Forgetting to state the assumptions (especially independence).