Why the answer changes every run
If you run a probability simulation twice, you rarely get the same estimate. Both are slightly off from the true value, and they are off in different directions. The question is how far off they are likely to be, and how that changes when you add more runs.
The short answer is that the typical error shrinks in proportion to one divided by the square root of the number of trials. That makes accuracy expensive, and it is worth understanding before you decide how long to let a program run.
The square root rule
Suppose each trial is a success with true probability p, and you run n independent trials. The estimate is the fraction of successes. Its typical error, called the standard error, is:
square root of (p x (1 - p) / n)
The numerator p x (1 - p) is largest at p = 0.5, where it equals 0.25. For other probabilities it is smaller. The key feature is the n in the denominator under the square root.
Because of the square root:
- Four times as many trials halves the typical error.
- A hundred times as many trials cuts it to a tenth.
- To gain one extra decimal digit of accuracy, you need about a hundred times the work.
Worked figures for a fair coin
Take p = 0.5, so p x (1 - p) = 0.25. These are illustrations of the formula, not results from any particular program.
| Trials (n) | Standard error |
|---|---|
| 100 | square root of 0.0025 = 0.05 |
| 10,000 | square root of 0.000025 = 0.005 |
| 1,000,000 | square root of 0.00000025 = 0.0005 |
So with 100 trials the estimate typically misses by about 5 percentage points, with 10,000 trials by about half a percentage point, and with a million trials by about 0.05 percentage points.
A common rule of thumb is that about 95% of estimates fall within two standard errors of the true value. With 10,000 trials and p = 0.5, that is within about 0.01, or one percentage point. Seeing 0.495 or 0.508 would be unremarkable. This relies on the normal distribution as an approximation, which works well once there are enough successes and failures.
Working backwards: choosing n
You can turn the formula around. If you want a 95% margin of about 0.01 for a probability near 0.5, you need two standard errors to equal 0.01, so the standard error must be 0.005. Then 0.25 / n = 0.000025, which gives n = 10,000.
To get a margin of 0.001, the standard error must be 0.0005, which needs n = 1,000,000. This is why people talk about running “a million trials”: it is the point where a probability near one half is typically pinned down to the third decimal place.
For probabilities far from 0.5 the requirement is lower in absolute terms. At p = 0.1, p x (1 - p) = 0.09, so the standard error with 10,000 trials is the square root of 0.000009, about 0.003.
Rare events are the hard case
The formula measures absolute error. When the event is rare, absolute error is a poor guide, because a small absolute error can still be a large share of the thing you are measuring.
Imagine estimating a probability of 0.001 with 10,000 trials. You expect about 10 successes. The standard error is the square root of (0.001 x 0.999 / 10,000), about 0.0003. That is roughly 30% of the value itself. The estimate might plausibly land anywhere from about 0.0004 to 0.0016.
For rare events, think in terms of the number of successes you observe. Having at least a few hundred successes generally gives a reasonably stable relative estimate, which can mean a very large number of trials when the chance is tiny. Very long odds, such as lottery odds, are impractical to estimate by brute-force simulation for exactly this reason.
What more trials cannot fix
More runs reduce random error, which is the sampling noise described above. They do not reduce errors in the model.
- If the code has a bug, such as the wrong rule for a game, a billion trials will confirm the wrong answer very precisely.
- If the random numbers are poor quality, extra trials may not help, since the issue is in the generator rather than the count.
- If the quantity is very sensitive to rare, extreme outcomes, the estimate can converge slowly even with many runs.
A useful check is to run the simulation with the same number of trials several times and see how much the answers scatter. If the scatter matches the standard error formula, the simulation is behaving as sampling theory predicts.
Connecting to the law of large numbers
The law of large numbers says the observed fraction approaches the true probability as trials increase. The square root rule adds the missing detail: how fast. Convergence is real but slow, and it never promises that a particular finite run is close. In a short run, results can look far from expected, and that says nothing about whether a game will “even out” later. Each trial remains independent, and past results do not change future odds.
A practical way to choose
- Decide how precise the answer needs to be. Often two decimal places are enough.
- Use the formula with p = 0.5 as a cautious worst case to find a trial count.
- Run it several times and look at the spread.
- If the spread is too large for your purpose, multiply the trials by 100 to gain one more digit, or look for a smarter way to answer the question.
Remember that the result is an estimate. When the question matters for money, such as understanding a game with a house edge, a simulation is a tool for understanding, not for finding a reliable way to win. Gambling can be harmful, and support is available from local services.