Estimating P(two heads) with 20 simulated coin flips
We're flipping two coins together. What's the chance both land on heads?
First, the theory. Two coins have four equally likely outcomes: HH, HT, TH, and TT.
Only one of those four is HH, so the theoretical probability is one fourth, or 0.25.
But what if we didn't know the theory? We could run a simulation. Let's flip two coins twenty times.
Here are the results of all twenty trials.
Now we count the trials that landed HH. There are five of them.
Five out of twenty trials. That's our experimental estimate of the probability.
Five over twenty equals 0.25 — the same as the theoretical chance. With more trials, our estimate would settle even closer.
Simulations let us estimate the probability of compound events by counting how often they happen.