Why Flipping a Coin 1000 Times Reveals the Truth
What You'll Learn
How randomness becomes predictable when you repeat it enough times — and how to use Python to simulate thousands of experiments and discover hidden truths.
Part 1
Randomness Has a Secret
Flip a coin. You can't predict whether it'll be heads or tails. It's random. Totally unpredictable.
Now flip it 10 times. You might get 7 heads and 3 tails. That doesn't seem like 50/50 at all. Random, right?
But flip it 1,000 times. Something strange happens: you'll get very close to 500 heads and 500 tails. Flip it 10,000 times? Even closer to exactly 50/50.
The more you repeat a random process, the closer the results get to the "true" probability. This is one of the most important ideas in all of mathematics. It's called the Law of Large Numbers, and it's why casinos always win in the long run, why polls can predict elections, and why insurance companies stay in business.
Today, we're going to see it happen with our own eyes — by making Python flip coins thousands of times.
Part 2
A Few Flips: Chaos
Let's start small. Flip a coin 10 times and see what happens:
Run it 5 or 6 times. Sometimes you'll get 70% heads. Sometimes 30%. Sometimes exactly 50%. With only 10 flips, anything can happen. The results are all over the place.
This is what randomness looks like in small doses: unpredictable, messy, unreliable.
Part 3
A Thousand Flips: Order From Chaos
Now let's go big. Same coin, same randomness — but way more flips:
New Things
{pct_heads:.1f} inside an f-string formats the number to 1 decimal place. So 49.7283 becomes 49.7.
{heads:5d} pads the number to 5 characters wide, right-aligned. Makes columns line up.
abs() gives the absolute value — the distance from zero. abs(-3.2) is 3.2. We use it to measure how far from 50% we are, regardless of direction.
Now try changing flips to 10, then 100, then 1000, then 10000. Watch the distance from 50% shrink as you add more flips. That's the Law of Large Numbers in action.
Part 4
Watching It Converge
Let's track the percentage after every batch of flips and watch it settle toward 50%:
Run it several times. With 10 flips, the dot bounces all over. With 5000 flips, it's always right near the center line. More repetition = more truth.
Part 5
Drawing the Convergence
Let's build an actual chart that shows the heads percentage over time. This is like a graph turned sideways:
The top of the chart (fewer total flips) shows the dot jumping around. The bottom (more flips) shows it hugging the 50% line. That visual IS the Law of Large Numbers.
Part 6
Beyond Coins: Dice
The Law of Large Numbers works for any random process, not just coins. Let's try dice — each face should show up about 1/6 of the time (16.67%):
Try 100 rolls — the faces will be uneven. Try 10000 — they'll all be close to 16.7%. The die isn't changing. The randomness isn't changing. But the larger sample reveals the truth that was there all along.
Part 7
Discovering a Cheat
Here's where it gets really interesting. What if the coin isn't fair? What if someone rigged it to land on heads 60% of the time? Could you detect that?
The Power of Large Samples
With 10 flips, a rigged coin looks normal — you can't tell it from a fair one.
With 100 flips, it starts to look suspicious.
With 10,000 flips, the bias is unmistakable — it's clearly landing on heads way more than 50%.
More data = more truth. This is why scientists run experiments hundreds of times, why polls survey thousands of people, and why "I tried it once and it didn't work" isn't a reliable conclusion.
Part 8
Simulation: The Birthday Surprise
Here's a famous puzzle: in a class of 23 students, what's the probability that two students share a birthday? Most people guess around 5-10%. The real answer? Over 50%.
That sounds wrong. Let's use simulation to check:
We couldn't easily calculate this probability with basic math. But we can simulate it thousands of times and observe the answer. This is the power of combining programming with the Law of Large Numbers — you can discover truths that are hard to figure out any other way.
Part 9
The Probability Lab
Time to put everything together. This is an interactive lab that lets you choose any experiment from this lesson and run it yourself. Pick an experiment, enter a number, and watch the Law of Large Numbers do its work.
Try each one — start with a small number, then go bigger. Notice how the results get more predictable every time you increase the sample size.
Note: option 3 requires the birthday function from Part 8. If you want it to work standalone, you can copy the has_shared_birthday function to the top of this code cell and rename it has_birthday_match.
Part 10
Why This Matters in Real Life
The Law of Large Numbers isn't just a math trick. It's one of the most important ideas for understanding the world:
Real-World Applications
Medicine: A drug is tested on thousands of patients — not just one — because small samples are unreliable.
Polls: Asking 1,000 people predicts an election better than asking 10 friends.
Insurance: Companies can't predict when ONE person will get sick, but they can predict what percentage of a million people will.
Games: One hand of poker is luck. A thousand hands reveal who's actually skilled.
Science: A single experiment proves nothing. Repeated experiments reveal the truth.
And the flip side is equally important: small samples are misleading. "I tried that diet for a week and it didn't work" is like flipping a coin 5 times and concluding it's biased. You need more data.
Part 11
What You Just Did
You used Python to simulate thousands of random experiments and watched something remarkable: chaos became order. Individual coin flips are unpredictable, but thousands of coin flips are almost perfectly predictable.
You also learned to use simulation as a tool for discovery — when you can't calculate an answer with math (like the birthday problem), you can run the experiment 10,000 times and observe the answer.
The Big Idea
Never draw big conclusions from small samples. One trial, one test, one experience doesn't tell you the truth. But repeat it enough times, and the truth emerges. The more data you have, the clearer reality becomes. That's the Law of Large Numbers — and it applies to everything from coin flips to life decisions.
Thinking Questions
- If you flip a coin 10 times and get 8 heads, does that prove the coin is unfair? What about 100 flips with 80 heads? Where do you draw the line?
- Why do casinos always win in the long run, even though individual players sometimes win?
- Can you think of a time someone drew a big conclusion from a small sample? ("I tried X once and it didn't work, so X is bad.")
Challenges
Level Up
Challenge 1 · Monty Hall Problem
There are 3 doors. Behind one is a prize. You pick a door. The host opens a different door (one without the prize). Should you switch? Simulate 10,000 games — one where you always switch, one where you always stay. Compare win rates. The answer surprises everyone.
Challenge 2 · Dice Unfairness Detector
Create a rigged die that favors the number 6 (30% instead of 16.7%). Then build a detector that rolls the die N times and reports whether it seems fair. How many rolls does it take to reliably detect the cheat?
Challenge 3 · Convergence Racer
Run 5 separate coin flip experiments simultaneously. Track each one's heads percentage at checkpoints (100, 500, 1000, 5000 flips). Display all 5 converging toward 50%. It's like watching 5 runners all finish at the same place!
Summary
What You Learned
Thinking Skill
Statistical Thinking — understanding that random events become predictable over many repetitions. Small samples are unreliable; large samples reveal truth. Ask: "Is this based on enough data to be meaningful?"
Key Concept
The Law of Large Numbers: The more times you repeat a random experiment, the closer the observed results get to the true underlying probability. 10 flips = chaos. 10,000 flips = truth.
Python Concepts
Simulation — using loops + randomness to run experiments thousands of times
random.randint(a, b) — random integer between a and b
abs() — absolute value (distance from zero)
f"{value:.1f}" — format to 1 decimal place
f"{value:>5d}" — right-align in 5 characters
ASCII charts — using position calculations to draw data visually