Coin Flip Simulator
Simulate a fair coin toss for heads or tails decisions.
About the Coin Flip Simulator
The Coin Flip Simulator runs one or many virtual coin tosses in a single click and reports the count and percentage of heads and tails, the variance and standard deviation from expected, the z-score for statistical significance testing, and the longest run of consecutive identical outcomes. With the probability slider, you can simulate fair coins (50/50) or biased coins weighted toward heads (e.g., 60% heads, 40% tails) for teaching probability concepts.
For a single flip the tool is a digital coin you can use to settle trivial decisions (who goes first, who pays, who chooses the movie). For 100 or 1,000 flips it becomes a probability demonstration, showing how the empirical percentage converges toward the theoretical probability as sample size grows. For 10,000+ flips it's a stress test of the JavaScript PRNG, with the z-score revealing whether the generator is statistically fair (a z-score outside ±2 suggests a biased generator or rare event).
The simulator uses Math.random(), which is sufficient for casual use and educational demonstrations. For cryptographic randomness — e.g., choosing a random encryption key — use a tool backed by crypto.getRandomValues() like our PIN Code Generator.
How It Works
Each flip is simulated as Math.random() < p, where p is the probability of heads (default 0.5 for a fair coin). Math.random() returns a float in the range [0, 1) drawn from a uniform distribution, so comparing it to p gives a Bernoulli trial: heads with probability p, tails with probability 1-p.
The expected number of heads after n flips is n × p. For a fair coin with 100 flips, that's 50 heads. The actual count will deviate from this expectation due to random variance. The variance of a binomial distribution is n × p × (1-p), so for 100 fair flips it's 25, giving a standard deviation of 5. About 68% of trials will land within ±5 of 50 heads; 95% within ±10; 99.7% within ±15.
The z-score normalizes the deviation: z = (actual - expected) / stddev. A z-score of 0 means the result matches expectation exactly. A z-score of ±2 or beyond occurs in about 5% of trials and suggests either an unusual (but valid) result or a biased generator. A z-score beyond ±3 occurs in less than 0.3% of trials and warrants suspicion.
The longest-run tracker walks through the result sequence and counts consecutive identical outcomes. For a fair coin, the expected longest run in n flips is approximately log2(n) — so in 100 flips you'd expect a run of 6-7, and in 1,000 flips a run of 9-10. Much longer runs (e.g., 10+ in 100 flips) are statistically suspicious.
Worked Examples
Default: 100 flips, fair coin. Typical results: 48-52 heads, 48-52 tails, longest run of 6-7 consecutive identical outcomes. The z-score should be between -2 and +2 about 95% of the time. The result string (H/T sequence) shows the natural clustering — runs of 3-4 of the same face are common and don't indicate bias.
Bump it to 10,000 flips. The percentage of heads should now be much closer to 50% (typically 49.5-50.5%) due to the law of large numbers. The z-score should rarely exceed ±2. The longest run will typically be 12-15.
Try a biased coin: 60% heads, 1,000 flips. Expected heads = 600, expected tails = 400. Standard deviation = sqrt(1000 × 0.6 × 0.4) = 15.49. A result of 605 heads has z = (605-600)/15.49 = 0.32 — well within normal variance. A result of 700 heads would be z = 6.45, an extremely unlikely result for a fair 60/40 coin — suggesting either a bug or extreme luck.
For a single flip, the result is simply ‘H’ or ‘T’ (each with 50% probability). Use it to settle decisions when no physical coin is handy.
Test the gambler's fallacy: flip 1,000 times and look at the longest run. Many people believe a long run of heads means tails is ‘due’ — but each flip is independent, and the simulator will show runs of 6-7 heads (or tails) in 100 flips with no underlying bias.
When to Use This Tool
- Settling trivial decisions (who goes first, who chooses the restaurant) when no physical coin is available.
- Demonstrating the law of large numbers — percentage converges to 50% as flip count grows.
- Teaching binomial distribution, variance, standard deviation, and z-scores in a probability class.
- Testing whether a JS PRNG is statistically fair by running 10,000+ flips and checking the z-score.
- Simulating biased coins (e.g., 60% heads) for probability puzzles and homework problems.
- Demonstrating the gambler's fallacy: long runs of identical outcomes are normal and don't predict the next flip.
- Quick simulation of Bernoulli trials for A/B test power analysis.
Limitations & Disclaimer
This simulator uses Math.random(), a non-cryptographic pseudorandom number generator. It's statistically uniform but not suitable for cryptographic applications, gambling with real stakes, or any scenario requiring provable randomness. The maximum flip count is 100,000 per run for performance and memory reasons. The longest-run tracker resets on each click — for cross-session streak tracking, record results manually. The probability slider accepts 0% or 100% values, which produce deterministic outputs (always tails or always heads) — useful for testing but not for random decisions. See our disclaimer for full terms.
Frequently Asked Questions
Is this coin truly random?
It uses <code>Math.random()</code>, which is a uniform pseudorandom generator. Over millions of flips, the distribution will be statistically indistinguishable from a fair coin. For cryptographic randomness, use a tool backed by <code>crypto.getRandomValues()</code>.
Why don't I get exactly 50% heads after 100 flips?
Randomness produces variance. With 100 fair flips, the standard deviation is 5, so 68% of trials land between 45-55 heads, and 95% land between 40-60. Only over thousands of flips does the percentage reliably converge to 50% (law of large numbers).
What does the z-score tell me?
The z-score measures how far the actual heads count is from expected, in standard-deviation units. A z-score of ±2 or beyond occurs in about 5% of trials (statistically unusual but not impossible). Beyond ±3 is rare and suggests either extreme luck or a biased generator.
Can I simulate a weighted coin?
Yes. Adjust the “Probability of Heads” slider to any value from 0% (always tails) to 100% (always heads). A 60% setting simulates a coin weighted toward heads. This is useful for teaching conditional probability and Bayes' theorem.
What's the longest run I should expect?
For a fair coin, the expected longest run in n flips is approximately log2(n). So in 100 flips expect 6-7 in a row; in 1,000 flips expect 9-10; in 10,000 flips expect 12-14. Much longer runs are statistically suspicious but possible.
Can I flip multiple coins at once?
The count field lets you flip up to 100,000 coins in one click. For sequential single-flip decisions, set the count to 1 and click repeatedly. Each click is independent — previous results don't influence future ones (no gambler's fallacy).
Last updated: July 21, 2026 · Author: HT99 Tools Editorial Team · Reviewed by: HT99 Tools Editorial Team