Grade by Grade
B. Probability Distributions · Discrete Probability Distributions

Simulating Probability Distributions

B1.1 B1.3 B1.6 B1.7About 70 minutes
Learning goals
  • I can design a simulation for a random variable using dice, cards, random digits or a spreadsheet.
  • I can use a simulation to estimate a probability distribution and its expected value.
  • I can compare simulated results with a theoretical distribution and explain the differences.
  • I can use simulation for problems that are hard to solve with formulas.

Words to know

simulation
A model of a random process using a simpler random device (dice, cards, random numbers) so that the process can be repeated many times quickly.
trial
One complete run of the simulation, which produces one value of the random variable.
random digits
A sequence in which each digit 0 to 9 is equally likely and independent of the others.
RAND() and RANDBETWEEN
Spreadsheet functions. RAND() gives a random decimal from 0 up to 1; RANDBETWEEN(a, b) gives a random integer from a to b inclusive.

When the formula is hard, simulate

A cereal company puts one of 4 different toys in each box, each equally likely. How many boxes do you expect to buy to collect all 4? The distribution of that number is hard to work out with the tools in this unit. But you can simulate it: roll a 4-sided device (or draw from 4 card suits), record which toys you get, and count boxes until you have them all. Repeat 100 times, and you have a good estimate of the whole distribution.

Simulation is also how scientists, engineers and actuaries check their theory, and it is used for problems with no formula at all, such as wait times in a hospital emergency room or the spread of traffic at an intersection. In the unit Probability you used simulation to estimate single probabilities. Here you will use it to estimate whole distributions.

1. Modellist outcomes andtheir probabilities2. Assignrandom numbersto outcomes3. One trialgenerate numbers;record X4. Repeatmany trials(100 or more)5. Analysetable, histogram,mean; compareDesigning a simulationSteps 3 and 4 are where a spreadsheet saves hours.
Every simulation follows the same five steps. The model in step 1 must match the real situation, or the results will be wrong no matter how many trials you run.

Tools for assigning random numbers

  • Coin: p = 1/2.
  • Die: 6 equal outcomes; use 1–2 for p = 1/3, or re-roll some faces (for 4 outcomes, re-roll 5 and 6).
  • Cards: 4 suits for p = 1/4; 13 ranks for p = 1/13; drawing without replacement models dependent trials.
  • Random digits 0 to 9: one digit for probabilities in tenths (0–6 for p = 0.7), pairs 00 to 99 for hundredths.
  • Spreadsheet: =RANDBETWEEN(1,6) is a die roll; =IF(RAND()<0.7,1,0) is a success with probability 0.7; =COUNTIF(range, value) counts results.

The key is that the probabilities must match: if a success has probability 0.23, exactly 23 of the 100 two-digit numbers must mean success.

Worked example

Example 1: Simulating a binomial distribution with random digits

A player makes 70% of free throws. Use the 50 random digits shown to simulate 10 trials of 5 shots. Estimate the distribution and mean of X = number of makes and compare with B(5, 0.7).

  1. Assign digits 0 to 6 (7 of the 10 digits) to "make" and 7, 8, 9 to "miss".
  2. Split the digits into groups of 5. Each group is one trial. Count the digits 0 to 6 in each group.
  3. Results: 3, 4, 2, 3, 4, 4, 4, 4, 2, 3. Frequencies: X = 2 (2 times), 3 (3 times), 4 (5 times); 0, 1 and 5 did not occur.
  4. Simulated mean: (2 × 2 + 3 × 3 + 4 × 5)/10 = 33/10 = 3.3.
  5. Theory: E(X) = 5 × 0.7 = 3.5; P(X = 4) ≈ 0.360 and P(X = 5) ≈ 0.168.

Estimated mean 3.3 compared with 3.5. Ten trials are far too few to get a good picture: no trial gave 5 makes, even though that happens about 17% of the time. More trials give better estimates.

Random digits in groups of 5 (one group = 5 free throws; 0 to 6 = make)74852trial 1: X = 360574trial 2: X = 479380trial 3: X = 292752trial 4: X = 353093trial 5: X = 418561trial 6: X = 400831trial 7: X = 467162trial 8: X = 485982trial 9: X = 208281trial 10: X = 3
The 50 digits split into 10 trials of 5 shots. Shaded boxes (digits 0 to 6) are made shots.
Worked example

Example 2: The toy-collector problem

Design a simulation to estimate the expected number of cereal boxes needed to collect all 4 toys, and interpret the results of 200 simulated customers shown in the histogram.

  1. Model: each box contains toy 1, 2, 3 or 4, each with probability 1/4, independently.
  2. Assign: the suit of a card drawn with replacement from a deck (or RANDBETWEEN(1,4)) is the toy in one box.
  3. One trial: keep drawing until all 4 suits have appeared. X = number of draws.
  4. Repeat 200 times. The histogram shows the results: X ranges from 4 to 33, the mode is 5, and the distribution is strongly skewed right.
  5. The mean of the 200 simulated values was 8.73.

The simulation estimates E(X) ≈ 8.7 boxes. (With more advanced methods the exact answer is 4(1 + 1/2 + 1/3 + 1/4) = 25/3 ≈ 8.33; 8.73 is a reasonable estimate from 200 trials.) The long right tail means some unlucky customers need 20 or more boxes.

010203040164345256227168179191018114121413–151516+number of boxes boughtfrequency200 simulated customers: boxes needed to collect all 4 toys
Results of 200 simulated customers. Getting all 4 toys in the first 4 boxes happened 16 times (theory: 4!/4⁴ ≈ 9.4%, about 19 of 200). Notice the long tail to the right. The last two bars each group several values, so they are taller than any single value would be.
Worked example

Example 3: A spreadsheet simulation of 1000 trials

Set up a spreadsheet to simulate X = number of 6s in 4 rolls of a die, 1000 times, and compare P(X ≥ 1) with theory.

  1. In A1:D1 type =RANDBETWEEN(1,6) four times. In E1 type =COUNTIF(A1:D1,6). This is one trial.
  2. Select A1:E1 and fill down to row 1000.
  3. In G1:G5 type 0 to 4; in H1 type =COUNTIF(E$1:E$1000,G1) and fill down: this is the frequency table.
  4. Estimate P(X ≥ 1) = 1 − H1/1000.
  5. Theory: P(X ≥ 1) = 1 − (5/6)⁴ ≈ 0.518. Press the recalculate key (F9 in Excel) to run a fresh 1000 trials.

A typical run gives an estimate between about 0.49 and 0.55. Each recalculation changes the estimate a little: that is sampling variability.

How many trials?

The typical error of a simulated probability shrinks like 1/√(number of trials). Going from 100 to 10 000 trials (100 times as many) makes the typical error about 10 times smaller. For classwork, aim for at least 100 trials; with a spreadsheet, 1000 or more is easy.

Worked example

Example 4: Simulating dependent trials

In a class of 30 students, 12 take the bus. The teacher picks 5 students at random for a survey. Describe a simulation of X = number of bus riders chosen, and give the theoretical mean.

  1. The 5 students are different people, so this is sampling without replacement: hypergeometric with N = 30, r = 12, n = 5.
  2. Model with cards: take 30 cards, 12 red and 18 black (for example, 12 hearts and diamonds plus 18 clubs and spades). Shuffle, deal 5, count red cards.
  3. Put the 5 cards back and reshuffle between trials (not during a trial).
  4. Theoretical mean: E(X) = 5 × 12/30 = 2.

Deal without replacement within each trial to match the dependence. The simulated mean should be close to 2.

Just for fun

Scientists running some of the first computer simulations in the 1940s gave their method the code name "Monte Carlo", after the famous casino in Monaco. Today "Monte Carlo method" is the standard name for any simulation that uses random numbers, and no tuxedo is required.

Hands-on activity

Simulate the toy collector at home

You need: a standard deck of cards (or a 4-sided spinner made from paper, a pencil and a paper clip), pencil and paper.

  1. Let the 4 suits stand for the 4 toys.
  2. Draw a card, note its suit, put it back and shuffle. Keep going until you have seen all 4 suits. Record X = the number of draws.
  3. Repeat for 25 trials (share the work with family members if you can).
  4. Make a frequency table and a histogram, and find the mean of X.
  5. Compare your mean with the theoretical 25/3 ≈ 8.33 and your histogram's shape with the one in this lesson.
  6. Extension: how would you change the simulation if one toy were rare (say, probability 1/10)?

What to look for: a mean somewhere around 7 to 10 and a right-skewed histogram with most values between 5 and 11. For the extension, use random digits: 0 = rare toy, and 1–3, 4–6, 7–9 for the other three toys (each 3/10). The rare toy makes the expected number of boxes much larger.

Your turn

1

How would you use random digits to simulate a trial with probability of success 0.4?

2

How would you use two-digit random numbers 00 to 99 to simulate a success probability of 0.15?

3

Write a spreadsheet formula that gives 1 with probability 0.08 and 0 otherwise.

4

A simulation of 50 trials gives X = 0 (8 times), 1 (20), 2 (15), 3 (7). Estimate E(X).

5

Why should a simulation of dealing a 5-card hand draw cards without replacement within a trial?

6

A student simulates 20 trials and gets an estimate of 0.35 for a probability whose true value is 0.25. Does this prove the theory is wrong?

7

How would you simulate the sum of two dice with a spreadsheet?

More practice: warm-up

1

What does RANDBETWEEN(1,10) produce?

2

What is one complete run of a simulation called?

3

Which device models p = 1/2?

4

Do more trials usually give better or worse estimates?

5

Which digits would you use for p = 0.3?

More practice: on your own

1

Design a simulation for: "8% of hotel reservations are cancelled. A hotel has 10 reservations. Estimate the distribution of the number of cancellations."

2

Use these digits as 6 trials of 4 tosses of a fair coin (even digit = head): 2846 1357 9024 6611 3870 5502. Find X = heads in each trial and the mean.

3

A die is used to simulate 4 equally likely toys. Explain how.

4

A simulation of 400 rolls of two dice gives 72 sevens. Compare with theory.

5

Explain why a simulation can never give the exact theoretical probability, but can come as close as you want.

Challenge

1

The theoretical probability that a collector gets all 4 toys in exactly 4 boxes is 4!/4⁴. Explain this formula and compare with the simulation (16 of 200).

2

Design a simulation to estimate the probability that, in a group of 23 people, at least two share a birthday (ignore February 29). Describe steps 1 to 5.

3

You simulate the free-throw problem with 1000 trials and get a mean of 3.30 makes per 5 shots. Theory says 3.5. Should you suspect your simulation? (The σ of one trial is √(5 × 0.7 × 0.3) ≈ 1.02.)

Check your understanding

Quiz

1.

To simulate an event with probability 0.35 using two-digit random numbers 00 to 99, you could let success be...

2.

What is the main reason to run more trials in a simulation?

3.

Which spreadsheet formula simulates one roll of a die?

4.

A simulation of 40 trials gives X = 1 (10 times), 2 (20 times), 3 (10 times). What is the estimated E(X)?

5.

To simulate dealing 5 cards from a deck, cards within a trial should be drawn...

6.

Why is simulation useful for the toy-collector problem?

For parents and teachers

Big idea (B1.1, B1.6, B1.7): a simulation models a random process with a simple random device (dice, cards, random digits or spreadsheet functions) so that it can be repeated many times. The results estimate the whole probability distribution and its expected value, and they can check a theoretical model or replace one when the maths is too hard.

How to help: run the toy-collector activity together; it is a quick card game. Ask your teen how they matched each probability to random numbers, and whether their results look like the theory.

Common difficulties:

  • Assigning the wrong number of digits (00 to 35 is 36 numbers, not 35).
  • Using replacement when the real situation has none (or the reverse).
  • Drawing strong conclusions from too few trials.
  • Forgetting that a simulated answer is an estimate, not an exact value.