Skip to content
Toolcroft

Random Generators

Coin Flipper

Flip a virtual coin - or up to 10 at once. Tracks heads/tails history and running stats for your session. Optional weighted coin for probability experiments. All randomness via Web Crypto.

Click Flip (or press Space) to flip a coin.

How this coin flipper works

Every flip uses crypto.getRandomValues, the browser's cryptographically secure random number generator backed by the operating system's entropy pool. A 32-bit value is drawn and mapped to a probability in [0, 1). If that value is less than the heads probability (0.5 for a fair coin), the result is heads; otherwise tails. This avoids the weak distribution of Math.random() entirely.

Fair coins and the law of large numbers

A single flip is truly 50/50, but short sequences regularly show streaks; that's normal probability, not a bug. Over hundreds of flips the running heads/tails percentage converges toward 50%. This is the law of large numbers in action. The session stats bar lets you watch that convergence happen in real time.

Weighted coins for probability experiments

Enable the Weighted coin option to set a custom heads probability between 0% and 100%. A 70% coin will land heads roughly 7 in 10 times over many trials. This is a useful teaching tool for demonstrating how probability works, including why even a biased coin still produces occasional "wrong" streaks. It is not intended to be used for decisions where fairness matters.

Flipping multiple coins

Select 2–10 coins to flip simultaneously. Each coin is drawn independently from a separate random value, so there is no correlation between results. The combined heads and tails count for each flip round is logged to the history and tallied in the session stats.

The gambler's fallacy

The gambler's fallacy is the mistaken belief that past results influence future independent random events. After flipping 10 heads in a row, many people feel "tails is overdue". It isn't. Each individual flip has exactly a 50% chance of heads regardless of all previous results. The coin has no memory. The fallacy arises from correctly knowing that long sequences are rare - but that rarity is assessed before the sequence begins, not after 10 heads have already occurred.

This does not mean the Law of Large Numbers is wrong: over thousands of flips, the proportion will converge to 50%. But the mechanism is the accumulation of future fair flips diluting the streak, not the streak somehow "making up" for itself.

Teaching statistics with coin flips

  • Expected value: for n flips, you expect n/2 heads. The expected value is the long-run average, not a guarantee for any single experiment.
  • Standard deviation: the standard deviation of the number of heads in n flips is √(n × 0.5 × 0.5) = √(n/4). For 100 flips, σ = 5, so getting 40–60 heads is within two standard deviations and is expected about 95% of the time.
  • Binomial distribution: the exact probability of getting exactly k heads in n flips is given by the binomial formula: P(k) = C(n,k) × 0.5ⁿ, where C(n,k) is the combination (n choose k).