๐Ÿ“˜ CodingMarble Learn

Estimating Probability Using Simulation

A simulation imitates a chance process with random numbers so we can estimate a probability that is hard to calculate. Plan it: state the question, give each outcome a set of random digits that matches its probability, define one trial and what counts as the event, then repeat many trials. The relative frequency (event count รท trials) is the estimate, and it gets closer to the true probability as the number of trials grows (the law of large numbers).

๐ŸŽฌ Step-by-step story

  1. Chance model: a fair die. Each face has probability 1/6. Theory works here, but many questions are too hard for a formula.
  2. Plan a simulation: match each outcome to random digits. Digits 1โ€“6 are the faces; skip 0, 7, 8, 9.
  3. Run trials one at a time. Each result drops onto its column. Count how often a 6 shows.
  4. Relative frequency = event count รท trials. It jumps at first, then settles near 1/6.
  5. A harder event: at least one 6 in 4 rolls. Simulate 500 trials of 4 dice. The estimate is close to 0.518.
  6. Free play: run 10, 100 or 1000 trials and compare the estimate with the true value.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

๐Ÿค” Common doubts, cleared

If we know P(6) = 1/6, why simulate a die at all?

To check that the simulation works on an easy case. Then we trust it for hard questions where no formula is easy.

Why skip digits 0, 7, 8 and 9?

A die has 6 faces. Using only 1โ€“6 keeps every face equally likely; extra digits would give some faces more chances.

Why are the columns not exactly equal?

Each roll is random. With 60 rolls each face gets about 10, but some get 7 and some 13. That is normal.

Why does the blue line wobble at the start?

Each new result changes a small total a lot. Later, one result hardly moves the average, so the line flattens near the true value.

Why is "at least one 6 in 4 rolls" not 4 ร— 1/6?

4 ร— 1/6 counts rolls with two or more sixes several times. Use 1 โˆ’ P(no six) = 1 โˆ’ (5/6)โด โ‰ˆ 0.518.

Will 1000 trials always give 0.167 exactly?

No, but it will usually be within about 0.02. Press Run 1000 several times and see.

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

  1. Question: state what you want to estimate, e.g. P(at least one 6 in 4 rolls).
  2. 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.
  3. 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.
  4. Run: do many trials and record results.
  5. 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).

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

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

Practice quiz

1. In a simulation, the estimated probability is:
2. To model an event with probability 0.3 using one digit, use:
3. As the number of trials grows, the relative frequency:
4. P(at least one 6 in 4 rolls) by theory is about:
5. After 5 heads in a row, the chance of heads on a fair coin is:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is a simulation in probability?

Imitating a chance process with random numbers, many times, to estimate how likely an event is.

What is the difference between experimental and theoretical probability?

Theoretical comes from reasoning about equally likely outcomes; experimental comes from the relative frequency in actual or simulated trials.

How many trials should a simulation use?

As many as practical: hundreds or thousands. The estimate's typical error shrinks like 1 รท โˆš(trials).

Where this is taught

USA (Common Core, NGSS, AP)Grade 12Probability, Random Variables, and Probability Distributions

Learn first

Learn next

Related lessons

All Maths lessons