Why simulate?
The theoretical probability of an event comes from reasoning: a fair die has 6 equally likely faces, so P(6) = 1/6. The experimental (empirical) probability comes from doing it: roll many times and find the relative frequency = (number of times the event happened) รท (number of trials).
Some questions are hard to work out by theory, like "How many cereal boxes must I buy to collect all 6 toys?" A simulation imitates the random process using random numbers (from a calculator, a computer or a random digit table) so you can estimate the answer quickly and cheaply.
Designing a simulation: step by step
- Question: state what you want to estimate, e.g. P(at least one 6 in 4 rolls).
- Model: give each outcome random digits in the right proportion. For a 30% chance, use digits 0โ2 = "yes" and 3โ9 = "no". For a die, use 1โ6 and skip 0, 7, 8, 9. For 2-digit chances like 0.45, use 00โ44 = yes, 45โ99 = no.
- Trial: say exactly what one repetition is (e.g. read 4 usable digits) and what counts as the event. Say whether repeats are allowed (with replacement) or not.
- Run: do many trials and record results.
- Answer: estimate = event count รท number of trials, written in context.
Each trial must be independent and use the same rules, otherwise the estimate is biased.
The law of large numbers
With few trials the relative frequency can be far from the truth: 3 sixes in 10 rolls gives 0.3, almost double 1/6. As the number of trials grows, the relative frequency settles closer and closer to the true probability. This is the law of large numbers.
It works only in the long run. It does NOT mean that after many non-sixes a six is "due". The die has no memory; each roll is still 1/6. That wrong idea is called the gambler's fallacy.
A rough rule: the typical error of an estimate shrinks like 1 รท โ(number of trials). So 4 times as many trials halves the typical error.
Worked simulation and Try it
Example: A basketball player makes 70% of free throws. Estimate P(she makes all 3 shots).
- Model: digits 0โ6 = make, 7โ9 = miss.
- Trial: read 3 digits; event = all three are 0โ6.
- Digits 512 | 873 | 046 | 390 | 621 โ trials 1, 3 and 5 are all makes, trial 2 has 8 and 7, trial 4 has 9.
- Estimate from 5 trials: 3/5 = 0.6. With many more trials it settles near 0.7ยณ = 0.343, which shows why 5 trials are not enough.
Try it: Toss a coin 20 times and record the running proportion of heads after every toss. Draw it on a graph. Then press "Run 1000" in 3D free play and compare the wobbly start with the flat end.
Key formulas and definitions
- Relative frequency = event count รท number of trials
- Theoretical probability = favourable outcomes รท total equally likely outcomes
- Digits for probability p: give a fraction p of all digits to "yes"
- P(at least one) = 1 โ P(none); e.g. 1 โ (5/6)โด โ 0.518
- Typical error โ 1 รท โn (shrinks as trials n grow)
Worked examples
1. A spinner lands on red with probability 0.4. Assign random digits to model one spin.
Use one digit: 0โ3 = red (4 of 10 digits = 0.4), 4โ9 = not red.
2. In 50 simulated trials, the event happened 13 times. What is the estimate?
Relative frequency = 13 รท 50 = 0.26.
3. A family has 3 children; each child is equally likely a girl or boy. Plan a simulation for P(at least 2 girls).
Model: even digit = girl, odd = boy. Trial: read 3 digits. Event: at least 2 even digits. Run 100+ trials. Answer: count รท trials (theory: 4/8 = 0.5).
4. Using the digits 3 8 1 7 2 9 5 0 4 6 for the family model (even = girl), how many trials have at least 2 girls in the first three triples?
381 โ 8 is even: 1 girl (no). 729 โ 2: 1 girl (no). 504 โ 0, 4: 2 girls (yes). 1 of 3 trials, estimate 1/3, too few trials to trust.
5. A quiz has 5 true/false questions. Design a simulation for P(guessing at least 4 right).
Model: digit 0โ4 = right, 5โ9 = wrong. Trial: 5 digits. Event: at least 4 are 0โ4. Run many trials; theory gives 6/32 โ 0.19 for comparison.
6. A simulation of 400 trials gives 0.52 for "at least one 6 in 4 rolls". Is this reasonable?
Theory: 1 โ (5/6)โด = 1 โ 625/1296 โ 0.518. Typical error โ 1/โ400 = 0.05, and 0.52 is within 0.002 of the truth, so yes.
Common mistakes
- Using digits in the wrong proportion, e.g. 0โ4 for a 40% chance (that is 5 digits = 50%).
- Forgetting to skip unused digits (like 0, 7, 8, 9 for a die) or to state the rule for repeats.
- Trusting an estimate from very few trials. Ten trials can be far off; use hundreds.
- Believing in the gambler's fallacy: past results do not change the next independent trial.