Coin Flip

Flip a virtual coin — fair, fast, with running heads/tails tally.

How this works

A digital coin flip used to settle yes/no questions, pick who goes first, or break ties when neither side will give. The widget pulls a single random bit from `crypto.getRandomValues` (the same RNG browsers use for security tokens), so the result is exactly 50/50 — no biased Math.random shortcuts. A short tumble animation gives visible feedback that something happened, then the result locks in. The history strip keeps the last 30 results so you can see the flips you actually got rather than the one your memory says you should have, and the running tally is updated on every flip — useful for proving fairness or showing kids how the law of large numbers works.

The formula

bit ← crypto.getRandomValues(Uint8Array(1))[0] & 1 result ← bit == 0 ? Heads : Tails

crypto.getRandomValues fills a buffer with cryptographically-secure random bytes drawn from a CSPRNG seeded by the operating system. Masking with `& 1` keeps just the lowest bit, which is uniformly 0 or 1 — i.e. exactly 50/50. Math.random would have given the same statistical fairness for this use, but using getRandomValues lets us tell users "fair" without any caveats about implementation quirks.

Example calculation

  • Tap "Flip the coin".
  • A random byte is read; its lowest bit decides the result.
  • Bit = 0 → Heads. Bit = 1 → Tails.
  • After enough flips the heads/tails ratio converges to 50/50 — the law of large numbers in action.

Frequently asked questions

Is this actually fair, or biased toward one side?

Genuinely 50/50. Each flip pulls a fresh byte from the browser's cryptographic RNG and uses its lowest bit. There's no hidden state, no streak-correction, no "due for tails" logic. In a small sample (10–20 flips) you'll often see runs of 4–6 heads or tails in a row — that's normal random behaviour, not a bias. Run 1,000 flips and the count will sit within a few percent of 500/500.

Why does the coin "tumble" before showing the result?

Pure UX. The result is decided the instant you tap the button — the bit is pulled and stored — but a 480ms tumble gives the brain time to register that something happened. Showing the answer instantly feels broken ("did it even flip?"), and waiting longer than half a second feels slow. 480ms is roughly the duration of a real-world coin toss in the air.

Can I trust the result for important decisions?

Statistically, yes — the math is sound. But the bigger question is whether you should be flipping a coin for the decision at all. If you're using it because you genuinely don't have a preference (which way to walk for lunch, who picks the next movie), the coin is fine. If you're using it because two options are tied on apparent merit but you secretly hope for one, listen to your reaction the moment the coin lands — that gut response is more useful information than the flip itself.

Is there a way to do "best of 3" or "best of 5"?

Not as a built-in mode — but the running tally and history strip together cover the same ground. Flip three times, look at the count, take the side with two or more wins. That said, "best of N" doesn't actually change the odds: if you'd accept a single 50/50 flip, three flips with a majority rule is also 50/50. People reach for it when they want the appearance of more deliberation than they really have, which usually means the underlying decision deserves a different decision-making method, not more flips.

Related calculators