Coin Flip Simulator
Simulate fair coin tosses for heads or tails decisions.
About the Coin Flip Simulator
The Coin Flipper simulates flipping a coin — or many coins — with an optional bias. Set the bias to 50% for a fair coin, or push it higher or lower to simulate a weighted coin. The tool reports heads and tails counts, the deviation from expected, and a chi-squared statistic for testing whether the result is consistent with a fair coin.
A fair coin flip is the canonical example of a Bernoulli trial — a single experiment with two possible outcomes and a fixed probability. The binomial distribution describes the sum of n independent Bernoulli trials. For n flips with bias p, the expected number of heads is n * p and the standard deviation is sqrt(n * p * (1 - p)).
Physical coin flips are not perfectly fair. A 2009 study by Persi Diaconis and Susan Holmes at Stanford (published in the SIAM Review, vol. 51, no. 2) found that coins tend to land on the same side they started on about 51% of the time, due to the precession (wobble) of the coin in flight. The deviation is small but statistically detectable in large samples.
The bias slider lets you simulate weighted coins. A bias of 60% means heads comes up 60% of the time — useful for teaching how a small bias becomes obvious with enough flips. After 100 flips, a 60/40 split is statistically distinguishable from 50/50; after 1000 flips, even a 52/48 bias is detectable.
How It Works
The tool generates flips random numbers in [0, 1) via Math.random(). For each number r, if r < bias, the result is ‘Heads’; otherwise it is ‘Tails’. This is the standard inverse-CDF method for sampling from a Bernoulli distribution with parameter p = bias.
For a single flip, the output is simply ‘Heads’ or ‘Tails’. For multiple flips, the output shows the count and percentage of each outcome, plus a chi-squared goodness-of-fit statistic that tests whether the observed distribution matches the expected distribution under the chosen bias.
The chi-squared statistic for a 2-outcome test is (observed_heads - expected_heads)^2 / expected_heads + (observed_tails - expected_tails)^2 / expected_tails. For a fair coin (p=0.5), the critical value at p=0.05 with 1 degree of freedom is 3.84 — if the chi-squared statistic exceeds 3.84, the result is statistically inconsistent with a fair coin.
The visual display shows the first 100 flips as colored circles (gold for heads, silver for tails). For larger numbers of flips, the display switches to a monospace text grid to avoid rendering thousands of DOM nodes.
Edge cases: a bias of 0% produces all tails; a bias of 100% produces all heads. A flip count of 0 is rejected. The flip count is capped at 10,000 to prevent browser performance issues — though even 10,000 flips take under a second on modern hardware.
Worked Examples
1 flip, 50% bias: returns Heads or Tails with equal probability. The canonical 50/50 decision maker.
100 flips, 50% bias: typically returns 45-55 heads. The standard deviation is sqrt(100 * 0.5 * 0.5) = 5, so 95% of runs fall within 50 +/- 10 heads (40 to 60). A result of 70/30 would have chi-squared = (70-50)^2/50 + (30-50)^2/50 = 8 + 8 = 16, well above 3.84 — statistically inconsistent with a fair coin.
1000 flips, 60% bias: expected heads = 600. A typical run returns 580-620 heads. The standard deviation is sqrt(1000 * 0.6 * 0.4) = 15.5, so 95% of runs fall within 600 +/- 31 heads.
10 flips, 50% bias: typically returns 4-6 heads. Small samples are noisy; a 7/3 split is not statistically significant (chi-squared = 1.6, below the 3.84 threshold). The law of large numbers kicks in only at larger sample sizes.
When to Use This Tool
- Settling a 50/50 decision when you cannot agree — who goes first, who pays for dinner, which movie to watch.
- Teaching probability — the law of large numbers, the central limit theorem, and the chi-squared test.
- Simulating A/B test outcomes when the true conversion rate is unknown.
- Demonstrating how small biases become detectable with enough samples.
- Generating random binary outcomes for Monte Carlo simulations or game design.
- Settling ties in board games or sports brackets when no other tiebreaker is available.
- Randomizing A/B test assignments for a quick demo of split testing.
Limitations & Disclaimer
The flipper uses JavaScript’s Math.random(), a pseudo-random number generator suitable for casual use and teaching but not for cryptographic purposes or real-money gambling. The chi-squared statistic is computed with 1 degree of freedom (two outcomes, one parameter estimated from the bias); for small samples (under 5 expected outcomes per category), use Fisher’s exact test instead. The bias slider applies per flip, not per session — each flip is independent. See our disclaimer for full terms.
Frequently Asked Questions
Is the coin flip truly random?
It uses JavaScript’s <code>Math.random()</code>, a pseudo-random number generator based on xorshift128+ (in V8). Statistical tests confirm uniformity for non-cryptographic purposes. For cryptographic uses or real-money gambling, use <code>crypto.getRandomValues()</code> or a hardware RNG. Physical coins are also not perfectly fair — see Diaconis et al. (2009) for the 51% same-side bias.
What is the law of large numbers?
As the number of flips increases, the observed proportion of heads converges to the true bias. After 10 flips, you might see 70% heads; after 1000 flips, the proportion is almost always within 3% of 50%. The standard deviation of the proportion shrinks as <code>1 / sqrt(n)</code>, so 4x more flips halves the noise.
What does the chi-squared statistic tell me?
It tests whether the observed distribution is consistent with the expected distribution (which is determined by the bias slider). A chi-squared value below 3.84 (the critical value at p=0.05 with 1 degree of freedom) means the result is plausible for the chosen bias; above 3.84, the result is statistically inconsistent. For a fair coin (50% bias), a chi-squared above 3.84 in 1 of every 20 runs is expected by chance.
Why does the same result come up many times in a row?
Streaks are expected in random sequences. The probability of k heads in a row is <code>0.5^k</code> for a fair coin. A 10-head streak has probability 1/1024 (0.1%), but in 10,000 flips, you would expect about 9 such streaks. The gambler’s fallacy is the mistaken belief that a streak must end — each flip remains 50/50.
How does the bias slider work?
It sets the probability of heads. A bias of 60% means each flip has a 60% chance of heads. The bias is applied per flip, not per session. Over many flips, the observed proportion of heads converges to the bias value.
Is the 51% same-side bias real?
Yes, for physical coins. Persi Diaconis, Susan Holmes, and Richard Montgomery published a 2007 study in <em>SIAM Review</em> showing that coins tend to land on the same side they started on about 51% of the time, due to precession (wobble) in flight. This is detectable with thousands of physical flips but not in casual use. Computer-generated coin flips do not have this bias unless explicitly modeled.
Last updated: September 9, 2026 · Author: HT99 Tools Editorial Team