← Math problems

Coin streaks 100 coin flips. Six in a row is almost certain.

Why doesn't randomness look random? Flip a fair coin 100 times and the longest run of one side is usually 6 or 7 flips long. People who invent "random" results avoid such runs and switch sides too often. Here you test it on yourself, on 100,000 simulations and on the history of the gambler's fallacy.

≈ 7longest run in 100 flips
80,7%chance of a run of 6 or more
headstailslongest run

The puzzle

Picture this: a teacher asks the class to flip a coin 100 times

Half the class really flips a coin, and the other half invents the results and writes them down so they "look random". The teacher glances at the two sheets and almost always spots the fake. How?

  1. 1

    The coin

    The coin is fair: heads and tails each come up with probability 1/2. Flips are independent, and the coin has no memory of earlier results.

  2. 2

    A run

    A run is a stretch of identical results in a row: HHHHH or TTTT. We care about the longest run of either side in 100 flips.

  3. 3

    A switch

    A switch happens when neighbouring flips differ: tails after heads or the other way round. 100 flips have 99 neighbouring pairs.

  4. 4

    The question

    How long is the longest run in 100 fair flips, typically? How many switches are there? And does tails become more likely after five heads in a row?

Intuition says

"Six heads in a row? That's suspicious"

In fact 100 flips contain a run of 6 or more 80.7% of the time, and the longest run averages about 7. Real randomness looks clumpy. What gives a fake away is how even it is.

Model assumptions

  • The coin is fair: 50/50.
  • Flips are independent of each other.
  • Runs of either side count.

If you count runs of heads only, the longest is about one shorter on average: around 6.

Round 1 · Guess

The longest run in 100 flips?

Lock in your answer before reading on. What longest run of one side do you expect in 100 fair flips?

4
15101520

Your answer will be compared with the exact distribution here.

Round 2 · Game

Invent 100 flips and try to fool the detector

Press "Heads" and "Tails", or type H and T in the box, until you have 100 "random" results. Meanwhile the page flips a real coin 100 times. The detector sees both sequences without labels and guesses which one a person made up. It looks at just two things: the longest run and the number of switches.

Flips0
Longest run0
Switches0

Flip 100 times for real

Longest run–
Switches–
Heads–

Longest runs of your flips

Theory for 100 flips: the longest run averages 6.98, is most often 6, and has a median of 7. Runs of 6 or more are highlighted.

Round 3 · Simulation

100,000 sequences of 100 flips

The computer flips a coin millions of times, splits the flips into sequences and finds the longest run and the number of switches in each. The line is the exact distribution, computed by dynamic programming; the dots are the simulation.

Flips per sequence
exact distribution simulation
–
Mean longest run
–
Mean number of switches
–

Longer sequence, longer run: roughly log₂ n

To make the longest run one flip longer you need roughly twice as many flips. The flips axis is logarithmic. Each dot is 2,000 simulated sequences of that length.

exact mean log₂ n (dashed) simulation
Round 4 · Five explanations

Why long runs are unavoidable

No single flip knows about the earlier ones. But a run can start in many places, and 100 flips give many such chances. Here are five ways to see it.

The gambler's fallacy

A coin has no memory

Five heads in a row, then tails50%chance of tails on flip six
Six heads in a row from the start1/64chance before the first flip

The gambler's fallacy is the belief that after a run of heads, tails is "due" because chance supposedly evens out. Six heads in a row really is unlikely, 1/64, but only before you start. Once five heads are in, the sixth flip is heads or tails with the same chance of 1/2.

Many starting points

A run can start at almost any flip

Any particular six flips are all the same with chance 2/64 = 1/32. But 100 flips contain 95 windows of six in a row, and each of them could become a run. Many small chances add up to a big one.

The law of small numbers

We expect 50/50 even in small samples

Exactly 5 heads in 1024,6%the rest are "uneven"
45 to 55 heads in 10072,9%over a quarter of the time it's further off

Amos Tversky and Daniel Kahneman called this "belief in the law of small numbers": people expect even a short stretch of a random sequence to resemble the overall picture. That is why invented sequences are too even in short stretches: heads and tails alternate in them more often than in real ones.

Count the switches

99 neighbouring pairs, each with chance 1/2

Expected number of switches49,599 · 1/2
Real sequences40–5995.6% of the time

Each pair of neighbouring flips differs with probability 1/2, independently of the other pairs. So the number of switches is binomial with n = 99 and p = 1/2. A real sequence has 60 or more switches only 2.2% of the time. People inventing flips often switch far more than that.

For formula lovers

The exact formula by dynamic programming

Ak(m) = number of length-m sequences whose runs are all shorter than k
Ak(m) = 2m for m < k;   Ak(m) = Ak(m−1) + Ak(m−2) + … + Ak(m−k+1) for m ≥ k
P(longest run ≥ k) = 1 − Ak(n) / 2n  →  n = 100, k = 6: 0,8068
E[longest run] = Σk≥1 P(run ≥ k) ≈ log₂ n + 1/3  →  n = 100: 6,98

The recursion's logic: the last run of the sequence has some length j from 1 to k−1, and before it sits a shorter valid sequence ending in the other side. The side of that last run is then fixed. For 100 flips and k = 6 this gives exactly 80.68%. The page computes all these numbers this way, with no approximation.

Round 5 · Going further

Roulette, "being due" and the hot hand

The gambler's fallacy can be checked on a million flips. Then we look at roulette with a zero, and at one of the subtlest stories in statistics: how a study of the "hot hand" in basketball turned out, 33 years later, to contain a hidden bias.

After k heads in a row, is tails more likely?

The simulation flips a coin a million times and, after every run of k heads, looks at what came next. Each press adds another million flips.

share of tails after k heads 50%

What the simulation shows

Roulette: red, black and zero

Chance of red on the next spin

Why the zero matters

A wheel has no memory, just like a coin. But on roulette red is not "half": the green zero takes part of the odds. A bet on red after any run of blacks wins with the same chance, 18/37 on a European wheel and 18/38 on an American one.

So a long run of blacks gives no edge at all, and the house edge stays fixed: 1/37 ≈ 2.7% of every bet on a European wheel.

The hot hand: a hidden trap in short sequences

In 1985 Gilovich, Vallone and Tversky tested whether a basketball player hits more often after several hits in a row. For each player they took the share of hits after a run of hits and compared it with the share after a run of misses. They found no difference, and the hot hand was declared a cognitive illusion. In 2018 Miller and Sanjurjo showed that this way of counting is biased: even for a fair coin, the share of heads after heads, averaged over players, is below 50%.

The smallest case: 4 flips, share of H after H

Shots per player
Run length before the shot
Average share per player
–
All shots pooled
–

Where does the bias come from? Each player gives a single number, however many runs he had. Sequences with long runs have many shots "after heads", almost all of them heads, yet such a sequence weighs in the average as much as a sequence with a single run. Pool all the shots instead and the share is exactly 50%. Once Miller and Sanjurjo corrected for this, they found signs of a hot hand in the controlled shooting experiment from the original paper.

Bonus · Fun facts

Things to tell your friends

26

Monte Carlo, 18 August 1913

At the Monte Carlo Casino a roulette wheel came up black 26 times in a row. Gamblers kept betting more on red, sure it was "due", and lost millions of francs. That is why the gambler's fallacy is also called the Monte Carlo fallacy.

1 : 137 M

How rare that run is

The chance that 26 spins of a European wheel, starting from a given one, all come up black is (18/37)²⁶, about 1 in 137 million. But thousands of wheels spinning for decades add up to a huge number of spins, so a run like that turns up somewhere sooner or later.

1971

"Belief in the law of small numbers"

That was the title of a 1971 paper by Amos Tversky and Daniel Kahneman showing that even scientists expect small samples to resemble the whole population too closely. Kahneman later received the Nobel Prize in economics for research on errors of judgement.

1985

The hot hand in basketball

Thomas Gilovich, Robert Vallone and Amos Tversky analysed shots by Philadelphia 76ers players and ran an experiment with Cornell University basketball players. They found no hot hand, and for decades the paper was the classic example of people seeing patterns in randomness.

2018

The Miller and Sanjurjo correction

Joshua Miller and Adam Sanjurjo published a paper in Econometrica showing that the 1985 method systematically understates the share of hits after a run of hits. After the correction, data from the same experiment point towards a hot hand. The debate about its size goes on.

Class trick

The teacher and two sheets

Statistics teachers have long shown this trick. One group flips a coin, the other makes up the results. The teacher finds the fake in seconds: the invented sequence has no long runs, and heads and tails alternate too often.

Discussion

What do you think?

Share your own explanation, an objection or a variant of the puzzle. Commenting needs a GitHub account.

Newsletter

New puzzles, explanations and discussions

I keep adding new puzzles, new ways to explain them and write-ups of the discussions they start. Leave your email and I'll write when something new is out. No spam, one-click unsubscribe.

The sign-up form will appear here soon.