Every dayRandom Generators

Coin Flip
simulator.

Flip one fair coin to settle a choice, or thousands to watch chance at work.

How it's worked out

Each flip takes 32 random bits from your browser's secure generator, crypto.getRandomValues, and turns them into heads or tails. The bits are even in number, so both faces get exactly half of the possible values, and no flip depends on the one before. A replay number swaps that source for a fixed starting value, so the same number and count give the same flips on any device. That is how the examples below open in the tool.

The count of heads in a batch follows the binomial distribution. For n flips of a fair coin, the chance of exactly k heads is the number of ways to place k heads among n flips, divided by every possible sequence.

P(k heads)\displaystyle P(k \text{ heads})=(nk)(12)n\displaystyle {}= \binom{n}{k} \left(\frac{1}{2}\right)^{n}

To call a result unusual, the tool runs an exact two-sided test. It adds up the chance of every count at least as far from an even split as yours, in either direction. If that total is under 5%, the split is unusual for a fair coin. Above 1,000 flips the counts get too big for ordinary arithmetic, so they are worked out with logarithms.

Streak chances use a recursion: flip by flip, the tool tracks how long the current run is and adds up the chance that no run ever reaches the length you ask about. It covers runs of either face, or of heads only, and gives exact figures, not a simulation.

Worked examples

A statistics class gets 60 heads in 100 flips

Replay number 374 gives 60 heads and 40 tails, with a longest run of 7 heads in a row. A student asks if the coin is biased.

A fair coin lands at least this far from 50 in either direction 5.69% of the time. That is just over the 5% line, so the split is ordinary. One more head would change the verdict: 61 heads has a two-sided chance of 3.52%. For 100 flips, every count from 40 to 60 counts as normal.

Open this example in the tool

A streak of 13 heads in 1,000 flips

Replay number 2 gives 495 heads, well inside the normal range of 469 to 531. Somewhere in the sequence sits a run of 13 heads in a row.

That looks suspicious, but the typical longest run for 1,000 flips is about 10.3, and a run of 13 or more of either face turns up in 11.4% of batches this size. A long streak is a normal part of a long random sequence. It says nothing about the next flip, which is still heads half the time.

Open this example in the tool

Ten thousand flips and the law of large numbers

Replay number 5 gives 5,043 heads, 50.43% of the flips. The share is much closer to 50% than the class's 60%, yet heads lead tails by 86, more than the class's lead of 20.

Both facts hold at once. The share settles toward one half as flips pile up, while the gap between the counts tends to grow, roughly with the square root of the number of flips. Here the two-sided chance is 39.5%, and anything from 4,902 to 5,098 heads is normal for 10,000 flips.

Open this example in the tool

Reading your result

The most likely count is still rare. Exactly 5 heads in 10 flips happens only 24.6% of the time, even though no other count is more likely. So a batch that misses an even split is the usual case, not a sign of a bad coin.

Normal is a range that widens. At the 5% level, 100 flips can give 40 to 60 heads, 1,000 flips 469 to 531, and 10,000 flips 4,902 to 5,098. The range grows in heads but shrinks as a share of the flips.

Unusual does not mean unfair. A fair coin gets flagged about 1 batch in 20, simply because the cut-off is 5%. A real bias shows up as the same lopsided result again and again over many batches, not as one odd one.

Streaks are longer than people guess. In 100 flips, a run of at least 6 of the same face shows up 80.7% of the time, and 7 or more 54.2%. Even 10 in a row turns up in 8.67% of batches. Mark Schilling describes a class test where students who invent 200 flips almost always write runs that are too short, while real tosses of 200 have a longest run of about 8.

Common mistakes

  • Expecting tails after a run of heads. The coin has no memory. After five heads, the next flip is still heads half the time. The chance that five chosen flips all land heads is 3.13%, but that is fixed before the first one, not after.
  • Mixing up "five in a row" with "a run of five somewhere". Five chosen flips all heads is 1 in 32. A run of five of one face somewhere in 100 flips happens 97.2% of the time. The streak table gives the second figure.
  • Reading the 5% line as proof. A count just past the line, like 61 heads in 100, is a reason to flip more, not a verdict on the coin.
  • Flipping until you like the answer. If you redo a flip for a choice until it says what you hoped, the coin did not decide. Agree what heads and tails mean before you flip, and accept the first one.

Questions people ask

For heads against tails, very nearly. A study of 350,757 flips by hand, led by František Bartoš, found heads came up 50.0% of the time. It also found a coin lands on the side it started on about 50.8% of the time, so hide the starting side if the call matters.

Sources