Random Coin Flip Generator
Last updated: 19 August 2026
Reviewed by Gavin ยท Research and drafting assisted by AI
Quick presets
crypto.getRandomValues on a 1-byte buffer, masked to 1 bit). Each flip is independent and uniformly distributed over {Heads, Tails}. The optional seed uses a non-cryptographic xorshift32 PRNG (only for reproducible demos โ do NOT use for security).Random Coin Flip Generator
The Random Coin Flip Generator uses the browser's built-in Web Crypto API to produce cryptographically unbiased coin flips, one at a time, or up to 100 in a single click. Each flip is independent, uniformly distributed over {Heads, Tails}, and reproducible when you supply a fixed seed.
This is the same source of randomness used by password managers, secure-session tools, and the crypto.randomBytes() primitive in Node.js, it's not a JavaScript Math.random() approximation, it's a true random bit drawn from the platform's CSPRNG (cryptographically secure pseudorandom number generator).
How to Use the Coin Flip Generator
- Choose the number of coins to flip (1 to 100). Default is 1.
- Click "Flip" to draw the results. Each coin shows a face (Heads = ๐, Tails = ๐ช), an index, and the side.
- Read the live tally, heads count, tails count, and the percentage breakdown of the current batch.
- (Optional) Tick "Fixed seed" if you want reproducible flips, entering any text string produces the same sequence of results on every reload. Useful for demonstrations, classroom exercises, or reproducible randomisation in research.
- Flip again to add to the session totals, the cumulative heads/tails counter and the last-10-batches table update automatically.
- Click "Reset totals" to clear the session history.
The generator uses crypto.getRandomValues() on a 1-byte buffer and masks the least significant bit to 1 bit, exactly the canonical pattern for drawing an unbiased bit from a uniform-byte CSPRNG. There is no modulo bias because the buffer is exactly 1 byte and the mask is exactly 1 bit.
The Math
A fair coin flip is the simplest possible probability experiment: each trial has exactly two outcomes (Heads, Tails) with equal probability (0.5 each), and successive trials are independent.
Single-flip probability
$$P(H) = P(T) = 0.5$$
A uniform random bit maps to one of the two outcomes. Drawing from crypto.getRandomValues(new Uint8Array(1))[0] & 1 gives 0 or 1 with exactly 50% probability, modulo bias is impossible because 256 = 2 ร 128, and we take only the lowest bit.
Multi-flip distribution
For N independent flips, the number of heads follows a binomial distribution B(N, 0.5):
- Mean (expected value): E[H] = N ร 0.5
- Variance: Var[H] = N ร 0.5 ร 0.5 = N/4
- Standard deviation: ฯ = โ(N/4)
For N = 100 flips, expect about 50 heads with a standard deviation of 5. About 95% of batches will land between 40 and 60 heads (the ยฑ2ฯ band). For N = 1000, expect about 500 heads with ฯ โ 15.8, about 95% land between 468 and 532. The session-totals table makes it easy to watch this convergence in real time: as you accumulate more flips, the overall H% tends to drift toward 50%.
Law of large numbers
The cumulative H% across many batches converges on 50%. This is the classic "the more times you flip, the closer the empirical frequency gets to the theoretical probability" result. Use the session-totals counter to demonstrate the law in a classroom, start with 1 flip (always 0% or 100%), flip a few batches of 100, and watch the cumulative H% settle toward 50%.
Worked Examples
Example 1: Settling a 50/50 decision
Two friends disagree about where to eat. One wants Italian, the other wants Thai. They agree: Heads = Italian, Tails = Thai. They flip a coin on this page. The result is Heads. Italian wins.
The flip itself is the canonical "p(h) = 0.5, p(t) = 0.5" experiment, there's no bias toward either choice unless the coin itself is unfair, which is impossible with this generator because every bit comes from crypto.getRandomValues.
Example 2: Sampling 100 coins for a statistics class
A statistics instructor assigns "flip a coin 100 times and record the number of heads." Students using this page get a clean, reproducible result in seconds. Expected outcome: somewhere between 40 and 60 heads (95% of batches). A result of 70 or 30 is rare (โ 1 in 800) and a good teaching prompt about the difference between the expected and observed frequencies.
Example 3: Reproducible randomisation with a seed
A researcher is running a pilot study and wants each subject assigned to control or treatment with 50% probability. To make the study reproducible (so other researchers can re-run it with the same assignments), they use a fixed seed, for example, the subject's enrolment number.
The seed is mixed through a FNV-1a hash, then a xorshift32 PRNG is initialised with the hash. The first draw goes to subject 1, the second to subject 2, and so on. Every researcher with the same seed sees the same assignments. The session-totals table shows the cumulative H% across all subjects in the study.
Example 4: Quick streak detection
You flip 5 coins. The result is H, H, T, H, T. That's 3 heads and 2 tails, not a streak, but a 60% heads rate over a 5-coin sample, which is well within the ยฑ2ฯ band for a binomial(5, 0.5) experiment (ฯ = โ(5/4) โ 1.12, so ยฑ2ฯ = 2.24, meaning anything from 0.38 to 4.62 heads is statistically normal at 95% confidence). The tool's batch-by-batch table makes it easy to spot streaks across many flips.
Example 5: Verifying the CSPRNG is unbiased
Run 10 batches of 100 flips. The H-count for each batch should land in the range 35 to 65 (the wider ยฑ3ฯ band catches about 99.7% of batches). If a batch falls outside, you may have found a real bias in your platform's CSPRNG, this has happened historically (notably the 2006 Debian OpenSSL bug, where a maintainer's code change reduced the entropy pool to a single process ID and produced extremely biased output). Modern browsers are patched, but the test is still a useful classroom exercise on randomness hygiene.
Where It Shows Up
Coin flips are the canonical randomisation primitive, the simplest unbiased source of binary outcomes. They show up everywhere a "yes/no" decision has to be fair:
- Quick decisions, settling 50/50 disagreements, picking between two restaurants, choosing who goes first in a game.
- Games and tabletop RPGs, initiative order, hit/miss resolution in simple combat systems, coin-flip spells (e.g. "Flip a coin. If heads, the target is confused.").
- Sports, official coin tosses at the start of American football games (and many other sports), used to determine kickoff vs. receive and which end zone to defend.
- Research methodology, random assignment of subjects to control/treatment groups, randomisation in clinical trials (often computer-generated for reproducibility, but coin-flip logic is the foundation).
- Cryptography, coin flips are the simplest possible source of unbiased entropy, and they form the conceptual foundation for "1 bit of randomness" used in key generation, nonces, and IVs.
- Lotteries and raffles, coin flips are the seed primitive for "binary draw with replacement" systems used in small-scale promotions.
- Teaching, probability and statistics classes use coin flips to introduce sample space, expected value, variance, the law of large numbers, and hypothesis testing.
Common Mistakes
1. Confusing "fair coin" with "weighted coin"
A fair coin has P(H) = P(T) = 0.5. A weighted coin (like a two-headed quarter or a bent penny) does NOT, but the math is the same except the probability shifts. This generator produces a strictly fair coin: P(H) = 0.5 by construction. If you need a weighted flip (say, 70% heads), you'd need a different tool or a modified mapping (e.g. draw a uniform float in [0,1) and check < 0.7 for heads).
2. Mistaking short-run imbalance for bias
A sample of 10 flips showing 7 heads is NOT evidence the coin is biased. The standard deviation for B(10, 0.5) is โ(10/4) โ 1.58, so 7 heads is about 1.27ฯ above the mean, well within the ยฑ2ฯ "normal" range. To meaningfully test for bias, you need hundreds or thousands of flips; the session-totals table helps you watch the cumulative H% converge on 50% as N grows.
3. Using Math.random() instead of crypto.getRandomValues()
A common (and dangerous) shortcut is Math.random() < 0.5 ? 'H' : 'T'. JavaScript's Math.random() is NOT cryptographically secure, V8 uses xorshift128+, which is fast but predictable. For any application where an adversary could benefit from predicting the coin flips (cryptographic nonces, security tokens, gambling where money is on the line), crypto.getRandomValues() is mandatory. This tool uses crypto.getRandomValues() always.
4. Modulo bias when mapping random integers
A common mistake: Math.floor(Math.random() * 3) % 2 to get a bit. If the random integer distribution is uniform over 0, 1, 2 (which it isn't, because Math.random() * 3 produces 0 to <3), the % 2 mapping produces a non-uniform bit because 0 and 2 both map to 0, and only 1 maps to 1. The correct pattern is the one this tool uses: draw a 1-byte uniform value, mask the least significant bit. Because 256 is exactly divisible by 2, there is no modulo bias.
5. Treating "Heads" as a hot/cold streak signal
Some people flip a coin repeatedly and assign meaning to the streak length ("I'm on a hot streak, I should keep flipping"). This is the gambler's fallacy, the coin has no memory, and each flip is independent. A 5-head streak does NOT make a tail "more likely" on the next flip; the probability is still 0.5. The session-totals table demonstrates this visually: cumulative H% converges on 50% regardless of recent streaks.
Frequently Asked Questions
Is the coin flip truly random? Yes, every flip draws a 1-byte uniform value from crypto.getRandomValues() (the Web Crypto API CSPRNG, which on modern browsers is backed by the operating system's entropy pool: /dev/urandom on Linux, BCryptGenRandom on Windows, SecRandomCopyBytes on macOS). The result is a true uniform bit, not a predictable PRNG output.
Why is Math.random() not used? JavaScript's Math.random() is a fast xorshift128+ PRNG that is NOT cryptographically secure. For any application where an adversary could benefit from predicting flips (cryptographic nonces, security tokens, gambling where money is on the line), crypto.getRandomValues() is mandatory. This tool uses crypto.getRandomValues() always.
What does the "Fixed seed" toggle do? It switches the generator from crypto.getRandomValues() to a deterministic xorshift32 PRNG initialised with a hash of your seed string. The flips become reproducible, the same seed produces the same sequence of results on every reload. This is useful for research and demonstrations; it is NOT secure and should not be used for anything sensitive.
Can I flip more than 100 coins at once? The current form caps at 100 coins per click to keep the result panel readable. For larger samples, click "Flip" multiple times, the session-totals counter accumulates all flips across the session.
How do I verify the coin is fair? Run 1000 or more flips in batches of 100. Plot or tabulate the H% per batch, for a fair coin, about 95% of batches should land within ยฑ2ฯ of 50% (i.e. between 40% and 60% for batches of 100). Any persistent bias outside that range suggests a problem with the CSPRNG or the mapping.
Is the result suitable for gambling? The output is cryptographically unbiased, but this tool is provided as-is for educational and recreational use. For any application with monetary stakes (online gambling, paid contests, legal randomisation), use a state-licensed randomisation service with regulatory oversight, not a web tool.
Why does the page say "H'" with an apostrophe? For visual clarity in the compact coin-cell display. The apostrophe disambiguates the single-character "H" (Heads) from any other context where "H" might appear (e.g. adjacent to "T" in a list).
Can I use this for research randomisation? Yes, enable "Fixed seed" and record the seed alongside the assignment output. Other researchers with the same seed will reproduce the exact assignment sequence.
**Q:**Can the Random Coin Flip Generator be used for professional or commercial purposes?A: Yes, the Random Coin Flip Generator provides mathematically correct results that are suitable for professional, commercial, and educational use. For the Random Coin Flip Generator, For the Random Coin Flip Generator, For high-stakes applications (medical, legal, financial), verify results with a domain expert. For the Random Coin Flip Generator, the Random Coin Flip Generator formulas used are well-established and validated against reference standards.
**Q:**For the Random Coin Flip Generator, How often are the underlying formulas updated?A: the Random Coin Flip Generator formulas are based on established scientific, mathematical, or industry-standard references and rarely require updates. When standards change (e.g., new physical constants, revised tax brackets, updated standards), the Random Coin Flip Generator is updated to reflect the current authoritative source. For the Random Coin Flip Generator, For the Random Coin Flip Generator, Each calculator's references section lists the specific sources used.
References
- W3C Recommendation "Web Cryptography API Level 1" (26 January 2017), the W3C specification that defines
crypto.getRandomValues(). - MDN Web Docs,
crypto.getRandomValues()reference and compatibility tables. - RFC 4086, "Randomness Requirements for Security" (D. Eastlake, J. Schiller, S. Crocker, June 2006), best-current-practice on CSPRNGs and entropy sources.
- NIST Special Publication 800-90A, "Recommendation for Random Number Generation Using Deterministic Random Bit Generators" (revised June 2015).
- FNV-1a hash function, the basis for the seed-mixing step used in this tool.
- Marsaglia, G. (2003), "Xorshift RNGs", the canonical reference for the xorshift32 family used here for reproducible-mode flips.