AP® Computer Science Principles · Big Idea 3 · Topic 3.16
Randomness and Bias in Simulations
Simulations use random number generators to copy the unpredictability of real events, like coin flips or weather. But randomness only varies the outcomes already coded in; it can't fix a model that left something out.
Real systems are unpredictable. A coin lands heads or tails, weather turns out clear or rainy, and nobody can say for certain which before it happens. A simulation tries to mimic that by using a random number generator, a program feature that produces values you can't predict in advance but that follow a known pattern overall. For a fair coin, the generator picks heads or tails with equal chance each time, just like flipping a real coin. That's what makes the simulation behave like the real thing instead of just repeating one fixed outcome.
Run a fair coin simulation 10 times and you might see 7 heads and 3 tails, or some other lopsided split. Small samples swing around. Run it 10000 times and the heads count settles in close to 5000, because the law of large numbers says results approach the true expected proportion as the sample grows. That's the mechanism: randomness creates variability at any size, but more trials make the overall pattern more reliable.
Reliable isn't the same as complete. If a weather simulation only ever outputs clear or rainy because the designer never coded snow as a possibility, running it 10000 more times just produces more clear and rainy days. It cannot invent an outcome that was never built into the model. That's a modeling bias, not a sampling problem, and no amount of extra runs fixes it. The same idea applies past simulations: a computing innovation trained only on certain data will be biased toward what it saw, no matter how much of that same data it processes.
Key terms
- Random number generator
- A program feature that produces unpredictable values following a set pattern, like equal odds for heads or tails.
- Expected value
- The average outcome you'd predict over many trials, such as n divided by 2 heads in n fair coin flips.
- Law of large numbers
- The principle that results get closer to the true expected proportion as the number of trials increases.
- Modeling bias
- A flaw where a simulation leaves out a real possibility because it was never coded in, not because too few trials ran.
Watch it explained
- How it worksHow does a random number generator reproduce the variability a real system has?
- Worked exampleShow me a coin flip simulation run 10 times and then the same one run 10000 times.
- Common mistakeWhy doesn't running a simulation more times fix a bias in what it chose to model?
- Ties togetherHow does bias in a simulation connect to bias in the data a computing innovation learns from?
Check yourself
End of topic.