How to design and run a simulation (5 steps)

By Jude Wallis · Published

State the assumption you are modeling, assign digits to the outcomes in proportion to their probabilities, define exactly what one trial is, run many trials, and estimate the probability as the proportion of trials meeting the condition. A simulation estimates a probability, it does not prove one.

AP Statistics: Unit 2 (topics 2.3 Estimating Probabilities Using Simulation, 2.10 The Binomial Distribution). Estimating probabilities with simulation is Unit 2 topic 2.3 of the Fall 2026 AP Statistics course, which treats a probability as a long-run relative frequency and ties the estimate to the law of large numbers, while topic 2.10 asks you to estimate binomial probabilities from simulated data.

The five steps of a simulation

A simulation models a random process with a device whose outcomes you can generate quickly: a table of random digits, a calculator command, coins, dice, or slips of paper. The steps stay the same no matter which device you pick.

  1. State the assumption you are modeling, including the probability of every outcome.
  2. Assign digits, or another chance device, to the outcomes in proportion to those probabilities.
  3. Define exactly what one trial is and what you record from it.
  4. Run many trials and keep a tally.
  5. Estimate the probability as the proportion of trials that met the condition.

Step 2 is where most of the arithmetic errors happen, so it gets the most space below. Steps 1 and 3 are where most of the exam points sit, because a reader has to be able to run your design without asking you a single question.

Step 1: state the assumption you are modeling

Write down the model you are treating as true before you touch any digits. It is usually a specific numerical claim: a coin is fair, a treatment has no effect, a shooter makes 60% of her free throws, four prize figures are equally likely.

Put it in numbers. "Assume each free throw is independent with probability 0.60 of going in" is a design someone else can follow, while "assume she is a good shooter" is not.

Simulations are often used to ask how surprising a real result would be if the assumption were true. That is the same logic behind a hypothesis test, described in what does a p-value mean.

Step 2: assign digits in proportion to the probabilities

The digits 0 through 9 are equally likely, so a single digit splits probability into tenths and a two-digit block splits it into hundredths. Match the size of the block to the probability you need.

Probability of successAssignmentWhy it works
0.500 to 4 success, 5 to 9 failure5 of the 10 digits
0.300 to 2 success, 3 to 9 failure3 of the 10 digits
0.600 to 5 success, 6 to 9 failure6 of the 10 digits
0.2500 to 24 success, 25 to 99 failure25 of the 100 blocks
0.3500 to 34 success, 35 to 99 failure35 of the 100 blocks

Two rules keep the assignment honest. Every outcome gets a share of digits equal to its probability, and no digit ever serves two outcomes. With more than two outcomes you split the same way: a spinner with probabilities 0.40, 0.35, and 0.25 takes blocks 00 to 39, 40 to 74, and 75 to 99.

Leftover digits and repeated digits

Two situations break the neat assignment, and each has a standard fix.

Probabilities that do not fit tenths or hundredths. A fair die gives each face probability 1/61/6, which is not a whole number of tenths or hundredths. Assign digits 1 through 6 to the six faces and leave 0, 7, 8, and 9 unused. When you hit an unused digit, skip it and read the next one. Skipping introduces no bias, because the six digits you kept are still equally likely.

Repeated digits. Whether you skip a repeat depends on the process. If you are choosing people or objects without replacement, a repeat would mean picking the same one twice, so skip it and read on. If the trials are independent repetitions, such as free throws or coin flips, a repeat is a genuine outcome and you keep it.

Settle both questions before you read a single digit, and write your decision into the design. A reader cannot check a simulation whose skipping rules were invented halfway through the run.

Steps 3 to 5: one trial, many trials, one proportion

Defining one trial means stating how many digits you read and what you record. "Read 5 digits, count how many fall in 0 to 5, and record whether that count is at least 4" is complete, because it fixes both the reading and the recording.

Then repeat until the proportion settles down. A hundred trials is a reasonable minimum by hand, and software runs thousands in a second. The law of large numbers is the reason this works: for independent trials, the long-run relative frequency of an event moves closer to a single value as the number of trials grows.

Finally, divide. The estimated probability is

p^=trials meeting the conditiontotal trials\hat{p} = \frac{\text{trials meeting the condition}}{\text{total trials}}

where p^\hat{p} (p-hat) is a sample proportion, the same statistic used later in inference for proportions.

Reading a line from a random digit table

A random digit table is a long string of digits printed in groups of five. The grouping is only there to keep your place, and it carries no meaning for your design. Pick a starting point, read left to right, and never go back over digits you have already used.

Take this line:

83657 12904 55381 27460 91738 40625 68193 37542

For a design that reads 5 digits per trial, the first trial is 8, 3, 6, 5, 7 and the second is 1, 2, 9, 0, 4. The printed spacing lines up with the trials here by coincidence; when a trial needs 3 digits or 7 digits, ignore the spaces and keep reading straight through. The first worked example below runs 8 trials on this exact line.

A simulation estimates a probability, it does not prove one

Every simulation result comes from a finite number of trials, so it carries sampling variability. Two students who run the same design starting at different places in the table will get different proportions, and both runs are correct.

That is why the number of trials matters and why you report the result as an estimate. Write "based on 100 trials, the estimated probability is 0.34" rather than "the probability is 0.34".

A simulation also cannot fix a wrong assumption. If you assign digits for p=0.60p = 0.60 when the true probability is 0.45, more trials only give you a sharper estimate of the wrong quantity.

Mistakes that break a simulation

  • Off-by-one digit ranges. Digits 0 to 5 is six digits and gives 0.60, while 0 to 4 is five digits and gives 0.50. Count the digits rather than eyeballing the endpoints.
  • Changing the skipping rule partway through the run, or skipping repeats in a setting where trials are independent.
  • Reporting the count of successful trials instead of the proportion.
  • Running 5 or 10 trials and then treating the result as the exact probability.
  • Reusing digits you already read, which makes the trials dependent.
  • Recording the wrong event, such as counting exactly 4 successes when the question asked for at least 4.

When the setting is binomial you can check a simulated estimate against the exact value with the binomial probability calculator. For more work on the underlying probability rules, use the probability rules practice set and the simulation topic page.

Design and run a free-throw simulation

A player makes 60% of her free throws, and the attempts are independent. Design a simulation that estimates the probability she makes at least 4 of her next 5 attempts, then run 8 trials on the line of digits above.

  1. State the assumption: each attempt is independent with probability 0.60 of a make and 0.40 of a miss.

  2. Assign digits: 0, 1, 2, 3, 4, and 5 are a make, which is 6 of the 10 digits and gives 0.60. The digits 6, 7, 8, and 9 are a miss, 4 of 10, which gives 0.40. No digit is left unused, and repeats are kept because the attempts are independent.

  3. Define one trial: read 5 digits, count the makes, and record whether that count is 4 or 5.

  4. Read the line 83657 12904 55381 27460 91738 40625 68193 37542 five digits at a time.

  5. Trial 1 reads 8, 3, 6, 5, 7. Only 3 and 5 are makes, so 2 makes. Condition not met.

  6. Trial 2 reads 1, 2, 9, 0, 4. Makes on 1, 2, 0, and 4, so 4 makes. Condition met.

  7. Trial 3 reads 5, 5, 3, 8, 1. Makes on 5, 5, 3, and 1, so 4 makes. Condition met.

  8. Trial 4 reads 2, 7, 4, 6, 0. Makes on 2, 4, and 0, so 3 makes. Condition not met.

  9. Trial 5 reads 9, 1, 7, 3, 8. Makes on 1 and 3, so 2 makes. Condition not met.

  10. Trial 6 reads 4, 0, 6, 2, 5. Makes on 4, 0, 2, and 5, so 4 makes. Condition met.

  11. Trial 7 reads 6, 8, 1, 9, 3. Makes on 1 and 3, so 2 makes. Condition not met.

  12. Trial 8 reads 3, 7, 5, 4, 2. Makes on 3, 5, 4, and 2, so 4 makes. Condition met.

  13. Count and divide: 4 of the 8 trials met the condition, so the estimate is 4/8=0.5004/8 = 0.500.

Based on these 8 trials the estimated probability is 0.500. The exact binomial value is P(X4)=(54)(0.60)4(0.40)+(0.60)5=0.2592+0.07776=0.33696P(X \ge 4) = \binom{5}{4}(0.60)^4(0.40) + (0.60)^5 = 0.2592 + 0.07776 = 0.33696, about 0.337. Eight trials is nowhere near enough for a stable estimate, which is the point: a simulation estimates a probability and needs many trials to estimate it well.

A design where repeated digits have to be skipped

A 10-member club picks 3 different members at random for a committee, and 3 of the 10 members have served on it before. Estimate the probability that at least 2 of the 3 chosen have served before, using the digits 28840 61193 55270 49236.

  1. State the assumption: every set of 3 different members is equally likely to be chosen.

  2. Assign digits: label the members 0 through 9, and let members 0, 1, and 2 be the three who have served before. All 10 digits are used, so no digit is skipped for being out of range.

  3. Set the repeat rule: the same member cannot be picked twice, so a digit repeated within a trial is skipped and the next digit is read. A digit that reappears in a later trial is fine, because each trial builds a fresh committee.

  4. Define one trial: read digits until you have 3 different ones, then count how many of them are 0, 1, or 2.

  5. Trial 1 reads 2, 8, 8 (a repeat, so skipped), 4, giving members 2, 8, and 4. That is 1 prior member. Condition not met.

  6. Trial 2 reads 0, 6, 1, giving members 0, 6, and 1. That is 2 prior members. Condition met.

  7. Trial 3 reads 1, 9, 3, giving members 1, 9, and 3. That is 1 prior member. Condition not met.

  8. Trial 4 reads 5, 5 (a repeat, so skipped), 2, 7, giving members 5, 2, and 7. That is 1 prior member. Condition not met.

  9. Trial 5 reads 0, 4, 9, giving members 0, 4, and 9. That is 1 prior member. Condition not met.

  10. Trial 6 reads 2, 3, 6, giving members 2, 3, and 6. That is 1 prior member. Condition not met.

  11. Count and divide: 1 of the 6 trials met the condition, so the estimate is 1/60.1671/6 \approx 0.167.

Based on these 6 trials the estimated probability is about 0.167. Counting the sets directly gives the exact value (32)(71)+(33)(70)(103)=21+11200.183\frac{\binom{3}{2}\binom{7}{1} + \binom{3}{3}\binom{7}{0}}{\binom{10}{3}} = \frac{21 + 1}{120} \approx 0.183. Six trials happened to land close, which is luck rather than evidence; the design is what earns the credit, and a real run would use at least 100 trials.

Frequently asked questions

How many trials does a simulation need?

There is no single required number, but more trials give a steadier estimate. A hundred trials is a reasonable floor for work done by hand, and software easily runs thousands. The law of large numbers is what guarantees the proportion settles toward the true probability as the trial count grows.

Do I always skip repeated digits?

No, and getting this backward is a common error. Skip repeats only when the process is a selection without replacement, so that the same person or object cannot be chosen twice. When trials are independent repetitions, such as coin flips or free throws, a repeated digit is a real outcome and you keep it.

What if the probability is not a clean tenth or hundredth?

Use a bigger block or a skip rule. A probability of 0.125 fits three-digit blocks, with 000 to 124 as success out of 1,000. A probability such as 1/61/6 has no finite decimal, so assign digits 1 to 6 to the six outcomes and skip 0, 7, 8, and 9 whenever they appear.

Can I use a calculator instead of a random digit table?

Yes. A command such as randInt(1, 6) or randInt(0, 9) does the same job, and software or an applet is faster for large trial counts. Whichever device you use, the design still has to state the assumption, the assignment of outcomes, and what one trial is.

Does a simulation prove that a probability is correct?

No. A simulation produces an estimate from a finite set of trials, and repeating the run with different digits gives a different estimate. Report it as an estimate based on a stated number of trials, and use exact probability rules when an exact answer is available.