What this coin flipper does
It tosses a fair virtual coin up to a million times and counts the results. You get the heads and tails tally, the longest streak, and how far the result is from a perfect 50/50 split. It's handy for settling a choice, running a classroom probability experiment, or seeing how real randomness behaves.
How the flips are made
Each flip is one bit from your browser's cryptographic random generator (crypto.getRandomValues). A random bit is 0 or 1 with equal chance, so heads and tails are exactly 50/50. Because there are exactly two outcomes, no rejection step is needed: a 32-bit value splits evenly into 32 fair flips, with no modulo bias.
The comparison with 50% uses the binomial distribution. For n fair flips:
The chance of a result at least as far from 50/50 as yours is the exact two-sided binomial probability, added up term by term. The chance of a streak at least as long as yours is counted exactly too, using the number of flip sequences in which every run is shorter.
Worked example
Flip 100 times. You'd expect 50 heads, with a standard deviation of √100 ÷ 2 = 5. So 45 to 55 heads is an ordinary result: about 73% of the time you'll land in that range. Getting 60 heads is 2 standard deviations away. The chance of being 10 or more heads away from 50, in either direction, is about 5.7%: unusual, but it happens.
More flips, closer to 50%
The count of heads wanders further from n ÷ 2 as you flip more, but the percentage gets closer to 50%. That's the law of large numbers.
| Flips | Expected heads | Typical spread (1 SD) | Spread as a share |
|---|---|---|---|
| 10 | 5 | ±1.58 | 15.81 points |
| 100 | 50 | ±5.00 | 5.00 points |
| 1,000 | 500 | ±15.81 | 1.58 points |
| 10,000 | 5,000 | ±50.00 | 0.50 points |
| 100,000 | 50,000 | ±158.11 | 0.16 points |
| 1,000,000 | 500,000 | ±500.00 | 0.05 points |
Streaks are longer than people expect
In n flips, the longest run of either heads or tails is typically about log₂(n) long. That's about 7 for 100 flips and about 10 for 1,000 flips. Mark Schilling's analysis found that 63% of sequences of 250 fair tosses contain a run of at least 8 heads or 8 tails. If a "random" list someone wrote by hand has no long streaks, it probably wasn't random.
Limitations
- This is a fair virtual coin. A real coin can be very slightly biased by how it's tossed and caught.
- Up to 1,000,000 flips at a time. The flip-by-flip sequence is shown for 100 flips or fewer.
- Each press of Flip again is a fresh, independent set of flips. Nothing is saved.