Skip to main content

Coin Flipper

Flip a virtual coin with animation. Track heads/tails counts, percentages, and streaks.

Reviewed by · Last reviewed

?

Using the Coin Flipper

  1. Click Flip Coin. The coin image rotates briefly and settles on either Heads or Tails. The animation is cosmetic - the result is chosen before the spin starts, so you are not biasing yourself by watching.
  2. Watch the statistics panel update: total flips, heads count, tails count, current streak, and a percentage bar split between the two outcomes.
  3. Reset anytime with the Reset button to clear the stats and start a fresh experiment.
  4. Scroll the history to see every flip in order, colour-coded for quick pattern scanning. This is the view students use when demonstrating the gambler's fallacy live in a classroom.
  5. Flip again as many times as you like - the CSPRNG has effectively inexhaustible entropy, so 10,000 consecutive flips are just as fair as one.

How Fairness Is Guaranteed in Software

Each flip draws a single byte from crypto.getRandomValues(new Uint8Array(1)), the Web Crypto API's cryptographically secure random source, and treats the low bit as heads or tails. Because 256 is even, there is zero modulo bias; the split is exactly 50/50 to within the precision of a CSPRNG, which is indistinguishable from true randomness to any computationally bounded observer. This matters for the teaching use case: a physical coin has a measurable bias (Persi Diaconis, Susan Holmes, and Richard Montgomery showed in their 2007 paper that a coin flipped and caught has roughly a 51% chance of landing the same side up), while the digital flip is a cleaner demonstrator of what a "truly fair" coin would do.

All computation happens in the Preact component. There is no fetch call per flip, no analytics beacon attached to each outcome, and no storage that outlives the tab. The stats panel is React state that resets when you reload.

When a Coin Flipper Is Useful

  • Teaching probability: watch how the heads ratio converges to 50% very slowly (the law of large numbers is visibly slow).
  • Demonstrating the gambler's fallacy: long streaks are common, and believing "tails is due" is a cognitive bias the history panel illustrates nicely.
  • Making a binary decision when neither choice has a clear advantage.
  • Simulating Bernoulli trials for a statistics homework problem or a Monte Carlo demo.
  • Generating random bits for a simple pedagogical example of a one-time pad (do not use for real keys).
  • Settling a tie in a meeting or a sports draft without reaching for an actual coin.

Streaks, Probabilities, and Common Misconceptions

  • Streak of 10. The probability of any specific 10-flip streak is (1/2)10 = 1/1024, so once per thousand 10-flip sequences on average. Seeing one on a live stats panel after a few hundred flips is entirely expected.
  • Gambler's fallacy. After nine heads, the probability of the next flip being heads is still exactly 0.5; the coin has no memory. Believing otherwise is one of the most-studied cognitive biases.
  • Clustering. Fair random sequences look more clustered than humans expect. True randomness has runs of same-side outcomes that look "non-random" to the eye.
  • 50/50 convergence is slow. After 100 flips the empirical ratio typically differs from 0.5 by several percentage points; the standard error of the ratio is roughly 1/(2√n), so you need 10,000 flips to reliably get within one percentage point.
  • Independence. Every flip is independent; the CSPRNG does not condition on prior outputs. Streaks arise by chance alone.
  • Physical coin bias. A real coin caught in the hand has about 51% same-side bias per Diaconis et al.; the software flip has none.

The Probability Theory Behind a Single Flip

A coin flip is the simplest Bernoulli trial: a single experiment with two mutually exclusive outcomes, conventionally labelled 1 (success) and 0 (failure), each with its own probability. Summing n independent Bernoulli trials gives a binomial distribution, X ~ B(n, 0.5) for a fair coin, whose expected value is n/2 and whose variance is n/4. The law of large numbers says the empirical ratio of heads converges to 0.5 as n grows, and the central limit theorem tells you the distribution of the ratio (after appropriate rescaling) is approximately normal. This is the ground on which modern frequentist statistics is built: Jakob Bernoulli worked out most of these ideas in his Ars Conjectandi, published posthumously in 1713, and Abraham de Moivre proved the normal approximation to the binomial in 1733.

Digital Flip vs. The Alternatives

A physical coin is ceremonially satisfying but subtly biased and impractical to use for thousands of flips. Python's random.choice(['H', 'T']) and R's sample generate the same thing programmatically with a seeded PRNG (useful for reproducibility) or with a CSPRNG if you reach for secrets. Hardware random number generators like the Intel RDRAND instruction or a quantum HRNG give certified entropy but are overkill. Classroom simulators like Seeing Theory (seeing-theory.brown.edu) run interactive probability demos that are more pedagogically rich than a flip button. The browser flipper wins when you want a quick fair coin with a visible streak history and a live percentage counter, without any install.

Frequently Asked Questions

Is each flip exactly 50/50?

Yes. The tool reads a byte from <code>crypto.getRandomValues</code> and uses a single bit, which is uniform 0 or 1 by the definition of the CSPRNG. There is zero modulo bias because the domain (0-255) is divided exactly in half by the bit test. The law of large numbers guarantees the empirical ratio converges to 0.5, but convergence is slow: expect a few percentage points of deviation even after hundreds of flips.

Why do I see long streaks of heads?

Streaks are a natural feature of independent fair trials. The probability of a run of exactly <em>k</em> same-side flips embedded in a long sequence is roughly 2 * (1/2)<sup>k</sup>, so streaks of 6-7 occur once every hundred flips or so on average. Human intuition often expects more alternation than randomness actually produces, which is why random sequences can look &quot;rigged&quot; to an untrained eye.

Is my flip data sent anywhere?

No. Every flip is generated locally by the browser&apos;s Web Crypto API, the statistics panel is React component state, and there is no network request per flip. You could disconnect from the internet after the page loads and the tool would keep functioning normally. The history and counts live only in the current tab and are erased when you close it.

What is the gambler&apos;s fallacy and how does this tool expose it?

The gambler&apos;s fallacy is the belief that past random outcomes affect future ones - for example, that after several heads, tails is &quot;due&quot;. The coin has no memory; every flip is an independent Bernoulli trial with probability 0.5 regardless of history. The tool exposes the fallacy by showing obvious streaks that feel surprising but are statistically ordinary, helping students internalise independence.

Are real coins exactly fair?

Not quite. Persi Diaconis, Susan Holmes, and Richard Montgomery analysed coin flips with high-speed cameras in 2007 and showed that a coin caught in the hand tends to land with the same side up that it started with, about 51% of the time, because of a small precession effect. A coin spun on a table has a much larger bias because of weight distribution. Digital coin flips avoid these physical biases entirely.

How can I tell if a sequence is truly random?

Use a statistical test: the chi-squared test checks if the heads / tails frequency is close to 50%, the runs test checks if the alternation pattern is consistent with independence, and the serial test checks for correlations between consecutive flips. NIST publishes a suite of such tests (SP 800-22) for certifying RNG quality. A CSPRNG like the one used here passes all of them by design.

What is Bernoulli&apos;s law of large numbers?

It says the empirical average of many independent repetitions of a random variable converges (in probability) to the expected value as the number of repetitions grows. For a fair coin, the heads ratio converges to 0.5. Jakob Bernoulli proved a version of this in <em>Ars Conjectandi</em> (1713); the modern strong form is due to Andrey Kolmogorov in the 1930s. It is why casinos win in the long run even on games with very small edges.

Can this tool simulate an unfair coin?

Not in the current UI, which assumes 50/50. For teaching Bayesian inference or biased-coin experiments you need a configurable probability, which is a straightforward feature request but not part of the current build. As a workaround, flip repeatedly and count only specific sequences (for example count only when the previous flip was heads) to emulate various conditional probabilities.

How long should I flip to get a reliable 50% ratio?

The standard error of the observed ratio is roughly 1/(2&radic;<em>n</em>). After 100 flips the ratio is typically within 5 percentage points of 0.5; after 10,000 within 0.5 percentage points; after a million within 0.05 percentage points. If you see a 52% heads ratio after 100 flips, that is statistically ordinary, not a sign the coin is broken.

Does the flip animation affect the outcome?

No. The random byte is drawn when you press the button and the animation plays deterministically to show the already-stored outcome. Spin duration and easing have no influence on the reported side.

More Fun & Utility