Designing a simulation
You cannot wait through a thousand real mornings to see how often a bus is late. What can stand in for them?
Where you are 14 in Basic probability
When you reach for it
Kenelm’s bus is late on 30\% of mornings. How often will it be late on two or more mornings in the same school week? Watching real weeks takes a year, and counting is awkward: a week has 2^5 = 32 patterns of late and on time, and they are not equally likely.
A simulation is a third way. You pick a chance process you can run in minutes (a coin, a spinner, a number cube, cards or random digits) and set it up so that each of its outcomes has the same probability as the real outcome it stands for. One complete run of it is a trial, and you record what each trial gave.
Reach for one when the real thing is slow or impossible to repeat, or when the question is about a compound event, several chance events at once, such as “late on at least two of five mornings”. This lesson designs simulations and runs a few trials by hand. Turning many trials into a number is running a simulation and estimating a probability, and why more trials help is the law of large numbers.
The procedure
Day 1: a device, an assignment and a trial
What a simulation copies. The real situation comes with a probability model: outcomes, each with a probability. The simulation copies the model and nothing else. A coin is nothing like a baby, but if the model gives each child a chance \displaystyle \frac{1}{2} of being a girl, heads has exactly that chance too. So every design is judged by one requirement: each simulated outcome must have the same probability as the real outcome it stands for.
What the usual devices give. Each has equally likely outcomes:
| Device | Outcomes | Each |
|---|---|---|
| coin | heads, tails | \displaystyle \frac{1}{2} |
| number cube | 1 to 6 | \displaystyle \frac{1}{6} |
| spinner, n equal sections | n | \displaystyle \frac{1}{n} |
| n cards, one drawn | n | \displaystyle \frac{1}{n} |
| random digit | 0 to 9 | \displaystyle \frac{1}{10} |
A drawn card goes back and the pile is shuffled before the next draw; otherwise the chances change.
Assigning outcomes. You assign the device’s outcomes: a group of them stands for each real outcome. Since they are equally likely, a group’s chance is its size over the total, as in the probability of an event. For a success with probability \displaystyle 0.7 = \frac{7}{10}, seven digits mean success and three mean failure:
Which seven does not matter. What matters is that every outcome of the device is assigned, since each one turns up sooner or later and the plan must say what it means.
Defining one trial. One trial is one complete copy of the thing the question is about. If the question is about a school week, a trial is five mornings, five digits, not one. Before running, settle what the device does in one trial, what counts as the event, and what you write down. Recording a count (the number of late mornings) rather than only yes or no lets the same trials answer a second question later.
The assumption inside the design. A fresh digit for each morning says every morning has the same chance whatever happened the day before, since a random digit has no memory. That is part of the model, not a fact about buses.
Day 2: random digits, compound events, and judging a design
Reading a random number table. In a random number table each digit is equally likely to be any of 0 to 9, unrelated to every other. The groups of five only keep your place; the spaces mean nothing. Choose a starting place before looking, then read in order along the row and on into the next. Never pick digits that look suitable: the table exists to take your choices out of the process. A random number generator on a calculator or computer does the same job; asked for a whole number from 1 to 100, it gives each the same chance.
Skipping digits. \displaystyle \frac{1}{3} cannot be made from tenths: three digits give 0.3, four give 0.4. Instead let 1, 2, 3 mean success and 4 to 9 failure, and skip 0, reading past it. The nine digits used are still equally likely, so a used digit is a success with probability \displaystyle \frac{3}{9} = \frac{1}{3}. Skipping costs time, never fairness, provided the skipped digits are fixed in advance.
Two-digit groups. 0.35 is 35 hundredths. Read pairs: the 100 pairs 00 to 99 are equally likely, so 00 to 34, which is 35 pairs, mean success and 35 to 99 failure. Pairs are read in order, straight across the printed groups of five. With skipping, pairs reach other fractions: for twelve equally likely months, use 01 to 12 and skip the rest.
Compound events. One trial uses one device outcome for each part of the question: three days of weather is three pairs. Decide whether the event happened once the whole trial is in. Trials do not overlap, and a trial the row runs out in the middle of is not counted.
Judging a design. A design is right when it passes four tests: each part of a trial has the right probability; it keeps that probability every time, whatever the parts before gave; one trial matches one whole run of the real situation; and what is recorded answers the question. Failing any one means the answers are about a different situation.
Worked examples
Day 1: choosing a device for a goalkeeper
Godfrey, a goalkeeper, saves 1 penalty in 4, so the model gives each penalty a save probability of \displaystyle \frac{1}{4}. Which of these could stand in for one penalty?
(a) Toss a coin; heads is a save. (b) Spin a spinner with four equal sections, one marked save. (c) Roll a number cube; 1 is a save, 2, 3 or 4 is not, and on 5 or 6 roll again. (d) Roll a number cube; 1 or 2 is a save. (e) Read one random digit; 0 or 1 is a save.
SolutionThe outcome standing for a save must have probability \displaystyle \frac{1}{4}.
(a) Heads has probability \displaystyle \frac{1}{2}. This does not work.
(b) Each of four equal sections has probability \displaystyle \frac{1}{4}, and one is a save. This works; that it looks nothing like soccer does not matter.
(c) A 5 or 6 is not used, so the roll that counts is one of 1, 2, 3, 4, equally likely, and one of them is a save: \displaystyle \frac{1}{4}. This works, by the same idea as skipping digits on Day 2.
(d) \displaystyle \frac{2}{6} = \frac{1}{3}. This does not work.
(e) \displaystyle \frac{2}{10} = \frac{1}{5}. This does not work, and no choice of single digits can, since 0.25 is not a whole number of tenths. Example 7 shows two ways round it.
Day 1: assigning digits for a phone signal
Hortense’s phone gets a signal at 60\% of the places she stops on her walks.
(a) Assign random digits to model one stop. (b) Jacinta suggests “1 to 6 means signal, 7 to 9 means no signal”. What is wrong, and how can it be mended? (c) Design a model of one stop with a number cube.
Solution(a) \displaystyle 60\% = \frac{6}{10}, so six digits mean a signal: 0 to 5 signal, 6 to 9 no signal. Each digit has probability \displaystyle \frac{1}{10}, so the six together have \displaystyle \frac{6}{10} = 0.6.
(b) The digit 0 is assigned to nothing. If it is simply skipped, the digits in use are the nine from 1 to 9, six of them signal, so the probability is \displaystyle \frac{6}{9} = \frac{2}{3}, about 0.67. The mend is to give 0 to no signal: 1 to 6 signal, and 7, 8, 9, 0 not, which is \displaystyle \frac{6}{10} again.
(c) 0.6 of six faces is 3.6 sixths, so no set of faces works as it stands. But \displaystyle 0.6 = \frac{3}{5}, so use five faces and roll again on the sixth: 1, 2, 3 signal, 4 and 5 no signal, 6 roll again. The roll that counts is one of five equally likely faces, three of them signal, so the probability is \displaystyle \frac{3}{5}.
Day 1: defining a trial for families of three children
A model treats each child as equally likely to be a girl or a boy, independently of the brothers and sisters. How likely is a family of three children to have at least two girls?
(a) Design a simulation: the device, one trial, and what to record. (b) Six trials with three coins gave \mathrm{HTH}, \mathrm{TTT}, \mathrm{HHT}, \mathrm{THT}, \mathrm{HHH}, \mathrm{TTH}. In how many did the event happen?
Solution(a) A coin matches one child: heads a girl, tails a boy, each \displaystyle \frac{1}{2}. The question is about a family, so one trial is three coins tossed, one family. A single toss is not a trial, since one child cannot show whether a family has two girls. Record the number of heads; the event happens when it is 2 or 3.
(b) The six families have 2, 0, 2, 1, 3 and 1 girls, so the event happened in 3 of the 6 trials. This small case can also be counted: listing the sample space gives eight equally likely families, of which \mathrm{HHH}, \mathrm{HHT}, \mathrm{HTH}, \mathrm{THH} have at least two girls, so the probability is \displaystyle \frac{4}{8} = \frac{1}{2}. Six trials will not always land this close.
Day 2: a late bus and a row of random digits
Kenelm’s bus is late on 30\% of mornings. Design a simulation for “late on at least two of the five mornings in a school week”, and run it on this row of a random number table, read from the start:
\displaystyle 30\% = \frac{3}{10}, so 0, 1, 2 mean late and 3 to 9 on time. One trial is one week, five digits. Record the number of late mornings; the event is “at least 2”.
The first five digits are 7, 3, 0, 2, 9: the 0 and the 2 are late mornings, so that week had 2 late and the event happened. The next five digits are the second week, and so on.
The weeks had 2, 1, 3, 0 and 4 late mornings, so the event happened in 3 of the 5 trials. That trials lined up with the printed groups of five is a coincidence of this question; Example 5 cuts across them. The counts also answer a second question: the bus was late on 10 of 25 mornings, a relative frequency of \displaystyle \frac{10}{25} = 0.4.
Day 2: two-digit groups for a hiker’s weather
Ivo plans a three-day hike. The forecast gives a 35\% chance of rain each day, and he treats the days as independent. Design a simulation for “at least one day of rain”, and run it on:
Single digits cannot make 35 hundredths, so read pairs: 00 to 34 (that is 35 pairs) mean rain and 35 to 99 mean dry. One trial is three pairs, six digits. Record the number of rainy days.
Reading pairs in order, the first trial is 58, 07, 91; the 91 takes the last digit of one printed group and the first of the next, which is why the spacing must be ignored.
| Trial | Pairs | Rainy days | At least one? |
|---|---|---|---|
| 1 | 58,\ 07,\ 91 | 1 | yes |
| 2 | 36,\ 44,\ 72 | 0 | no |
| 3 | 12,\ 85,\ 34 | 2 | yes |
| 4 | 69,\ 35,\ 50 | 0 | no |
| 5 | 96,\ 03,\ 81 | 1 | yes |
The event happened in 3 of the 5 trials. Note the edge: 34 is rain and 35 is dry.
Day 2: skipping digits on a game show
On a game show a prize sits behind one of three doors and the contestant picks one at random, so each night the chance of winning is \displaystyle \frac{1}{3}, independently of other nights. Lavinia is on for four nights. Design a simulation for “she wins on at least two nights”, and run it on:
\displaystyle \frac{1}{3} is not a whole number of tenths, so 1, 2, 3 mean a win, 4 to 9 a loss, and 0 is skipped. A used digit is one of nine equally likely, three of them wins, so a night is won with probability \displaystyle \frac{3}{9} = \frac{1}{3}. One trial is four used digits. Record the number of wins.
| Trial | Read | Used | Wins | Two or more? |
|---|---|---|---|---|
| 1 | 40815 | 4815 | 1 | no |
| 2 | 92067 | 9267 | 1 | no |
| 3 | 30418 | 3418 | 2 | yes |
| 4 | 25903 | 2593 | 2 | yes |
The event happened in 2 of the 4 trials. Four zeros were skipped, so twenty digits made sixteen nights. A number cube with 1 or 2 a win, \displaystyle \frac{2}{6} = \frac{1}{3}, would avoid skipping.
Day 2: judging five designs for a shootout
Godfrey saves a penalty with probability \displaystyle \frac{1}{4} and faces five penalties in a shootout. The question is how likely he is to save at least two. Judge each design.
(a) Toss a coin five times; each head is a save. (b) Shuffle 20 cards, 5 marked save, and deal five without putting any back. (c) Read five two-digit pairs; 00 to 24 is a save. (d) Read single digits; 1 is a save, 2, 3, 4 are not, and 0 and 5 to 9 are skipped. Five used digits make a trial. (e) Roll a number cube once; the number shown is the number of saves.
Solution(a) Wrong: a head has probability \displaystyle \frac{1}{2}.
(b) Wrong. The model gives every kick a save probability of \displaystyle \frac{1}{4}, whatever happened on the kicks before. The first card is right, \displaystyle \frac{5}{20} = \frac{1}{4}, but after a save card 4 of the 19 left are saves, \displaystyle \frac{4}{19}, and after a no-save card the chance is \displaystyle \frac{5}{19}. Each kick’s chance now changes with the kicks before, which makes them dependent events: a different model from the one in the question. Putting each card back and shuffling keeps every kick at \displaystyle \frac{1}{4}.
(c) Right: 25 of the 100 pairs, \displaystyle \frac{25}{100} = \frac{1}{4}, fresh for every kick.
(d) Right: one of the four used digits is a save, \displaystyle \frac{1}{4}. It skips six digits in ten, so it is slow, but slow is not wrong.
(e) Wrong: a trial must build the shootout kick by kick. One roll makes 0 saves impossible and 6 saves possible from five kicks, and gives each count the same chance, when five saves should be far rarer than one.
So (c) and (d) both work, and either is run exactly as in Examples 5 and 6.
Boundaries
A simulation answers questions about the model, not the world. If the bus is really late on 40\% of mornings and the design uses 30\%, every trial is wrong in the same direction. Exercise 14 treats the twelve months as equally likely birth months, ignoring that months differ in length; a simulation is only as close to the real situation as the model it copies.
A fresh digit for each part assumes the parts do not affect each other. A new pair for each day of Ivo’s hike says rain today does not change the chance tomorrow. If wet days come in runs where he walks, this design cannot show it; that needs a different model, not a different device.
Digits make tenths, pairs make hundredths. Thirds, sixths and twelfths cannot be made with any number of digits, because 10, 100, 1000 and so on are never divisible by 3; they need skipping or another device.
Reading the same row again gives no new trials. It repeats the old ones exactly.
A few trials are not a probability. They show how a design works, and their results can sit far from the true chance.
Where this goes next
Once a design is settled, the next step is to run it many times and divide: running a simulation and estimating a probability does that, and the law of large numbers explains why the relative frequency settles as trials pile up. Some questions have no fixed trial length, such as how many mornings pass before the first late bus; simulating a waiting time runs trials that stop when something happens, and the geometric distribution later gives the exact answer. Digits assigned to names on a list also pick a simple random sample, and repeating that pick is how sampling variability is studied.
Exercises
Day 1: choosing a device
- Each device is used once. Which give the event a probability of \displaystyle \frac{1}{2}? (a) A coin lands heads. (b) A number cube shows an even number. (c) A number cube shows 1 or 2. (d) A random digit is 0 to 4.
- A spinner is to stand for one day of a hike when the chance of rain is \displaystyle \frac{3}{8}. How many equal sections should it have, and how many marked rain?
- Jacinta models Hortense’s phone, which has a signal at 60\% of stops, with cards. Pile A has 10 cards with 6 marked signal; pile B has 5 cards with 3 marked. Which piles work, and what must she do after each draw?
Day 1: assigning digits
- Ivo’s bus is late on 20\% of mornings. Assign random digits to model one morning.
- Kenelm models a 70\% chance of a signal with “1 to 7 signal, 8 and 9 no signal”, and skips every 0. What probability does his design actually give? Mend it.
- The chance of rain on a hiking day is 0.5. Give two different ways to assign single random digits to model one day.
Day 1: defining a trial
- In the equal-chance model, with heads for a girl, one trial for a family of four children is four coin tosses. Six trials gave \mathrm{HHTT}, \mathrm{THTT}, \mathrm{HTHH}, \mathrm{TTTT}, \mathrm{HTHT}, \mathrm{HHHT}. In how many did the event “exactly two girls” happen?
- On a three-day hike the chance of rain is \displaystyle \frac{1}{2} each day, and the question is how likely rain is on all three days. Godfrey says “one trial is one toss of a coin, heads for rain”. What is wrong, and what is one trial?
Day 2: reading a random number table
- Kenelm’s bus is late on 30\% of mornings, with 0, 1, 2 meaning late. Each digit of the row 85120 \quad 39476 \quad 02118 \quad 64953 is one morning. On how many of these 20 mornings is the bus late?
- Use the same row in trials of five mornings, one school week each. In how many weeks is the bus late on at least two mornings?
- Hortense’s phone has a signal at 60\% of stops, with 0 to 5 meaning signal. Her walk has four stops, and the event is “a signal at all four”. Run as many trials as the row 31540 \quad 72519 \quad 04238 \quad 96015 allows. How many trials are there, and in how many does the event happen?
- A random number generator gives a whole number from 1 to 100, each equally likely. Assign its numbers to model a day with a 35\% chance of rain.
Day 2: pairs and skipping
- A goalkeeper saves 18\% of penalties. Assign two-digit pairs to model one penalty.
- Treat the twelve months as equally likely birth months. With pairs 01 to 12 for January to December and every other pair skipped, a trial is three people and the event is “at least two share a birth month”. Run as many trials as this row allows: 07451 \quad 19307 \quad 28640 \quad 51288 03107 \quad 70210 \quad 54093 \quad 10611. How many trials are there, and in how many does the event happen?
- Lavinia is on the game show of Example 6 for three nights, with 1, 2, 3 a win, 4 to 9 a loss and 0 skipped. The event is “she wins at least once”. Run as many complete trials as the row 70942 \quad 85160 \quad 30864 \quad 50973 allows. How many are there, and in how many does the event happen?
Day 2: judging a design
- For birth months, Godfrey uses pairs 01 to 24: 01 and 13 are January, 02 and 14 February, and so on, with 00 and 25 to 99 skipped. Is every month equally likely?
- For a three-day hike with a 35\% chance of rain each day, Ivo reads one digit per day with 0 to 3 meaning rain, and Kenelm spins a spinner with 20 equal sections, 7 marked rain, three times. Judge both designs.
- Hortense models Kenelm’s bus (30\% late) for a school week by dealing five cards, without putting any back, from 10 cards of which 3 are marked late. Judge the design.
Reasoning
- Explain why assigning 0 to 6 to success gives a probability of 0.7, and why it matters that every digit in a random number table is equally likely.
- Explain why skipping 0 does not spoil a design with 1, 2, 3 for success and 4 to 9 for failure.
- A simulation of Kenelm’s bus uses a fresh digit for each morning. Describe a real reason late mornings might bunch together, and what that would mean for the simulation’s answers.
- Explain why the assignment and the length of a trial must be decided before the digits are read.
Answers
- (a), (b) and (d): \displaystyle \frac{1}{2}, \displaystyle \frac{3}{6} = \frac{1}{2} and \displaystyle \frac{5}{10} = \frac{1}{2}. But (c) is \displaystyle \frac{2}{6} = \frac{1}{3}.
- 8 equal sections with 3 marked rain, each section \displaystyle \frac{1}{8}. A multiple, such as 16 with 6 marked, also works.
- Both work, since \displaystyle \frac{6}{10} = \frac{3}{5} = 0.6. She must put the card back and shuffle after each draw, so every stop has the same chance.
- Two digits for late, such as 0 and 1, and 2 to 9 on time: \displaystyle \frac{2}{10} = 0.2.
- \displaystyle \frac{7}{9} \approx 0.78, too high, since seven of the nine digits used mean signal. Mend it by counting 0 as no signal; then 1 to 7 is \displaystyle \frac{7}{10} = 0.7.
- For example 0 to 4 rain, or the even digits rain. Each gives rain five digits of ten, \displaystyle \frac{5}{10} = 0.5.
- 2 of the 6 trials. The numbers of girls are 2, 1, 3, 0, 2, 3.
- One toss is one day, but the question is about the whole hike. One trial is three tosses, and the event happens when all three are heads.
- 7 mornings: 3 late digits in 85120, none in 39476, 4 in 02118, none in 64953.
- 2 of the 4 weeks. The weeks had 3, 0, 4 and 0 late mornings.
- 5 trials, and the event happens in 1. The trials are 3154, 0725, 1904, 2389, 6015; only the first has no digit above 5.
- 1 to 35 rain and 36 to 100 dry: \displaystyle \frac{35}{100} = 0.35.
- 00 to 17 save and 18 to 99 no save: \displaystyle \frac{18}{100} = 0.18.
- 4 trials, and the event happens in 2. The pairs used are 07, 11, 07 (July twice), then 05, 12, 03, then 10, 02, 10 (October twice), then 09, 06, 11. Eight pairs are skipped.
- 5 complete trials, and the event happens in 2. The used digits are 7, 9, 4 (no win), then 2, 8, 5 (a win), 1, 6, 3 (two wins), 8, 6, 4 and 5, 9, 7 (no wins). The last digit, 3, starts a sixth trial the row does not finish, so it is not counted.
- Yes. Each month has two of the 24 pairs used, \displaystyle \frac{2}{24} = \frac{1}{12}. It skips 76 pairs in 100 rather than 88, so it wastes fewer.
- Ivo’s is wrong: \displaystyle \frac{4}{10} = 0.4, not 0.35. Kenelm’s is right: \displaystyle \frac{7}{20} = 0.35, and three spins make one trial of three days.
- Wrong. The first card is late with probability \displaystyle \frac{3}{10}, but after a late card only 2 of the 9 left are late, \displaystyle \frac{2}{9} \approx 0.22, so the mornings become dependent. It also makes four or five late mornings impossible, which a real week can have. Put each card back and shuffle.
- The ten digits are equally likely, each \displaystyle \frac{1}{10}, so seven together have \displaystyle \frac{7}{10} = 0.7. Counting digits only gives the probability because they are equally likely; if some came up more often, seven digits could stand for more or less than 0.7.
- The nine digits left are still equally likely to one another, so each used digit is one of nine with the same chance, and three of the nine mean success: \displaystyle \frac{3}{9} = \frac{1}{3}. Skipping changes how many digits are read, not the chance of each outcome.
- For example, road works or snow can make the bus late several mornings running, so one late morning makes the next more likely. A fresh digit each morning ignores this, so the simulation would show weeks with many late mornings less often than they really happen.
- Chosen after seeing the digits, they could be steered, even without meaning to, toward an expected result. Fixing them first leaves every trial to chance alone, which is what lets the digits stand in for the real situation.