Utility · Oct 14, 2026 · 4 min read

How Online Coin Flips and Dice Rolls Stay Fair: Modulo Bias, Streaks and Odds

Fair randomness has three traps: modulo bias in the code, streaks that look broken but are not, and the belief that the next flip is due. We measured all three.

Where the Randomness Comes From

Browsers offer two random number sources. Math.random is fast but not designed to be unpredictable, and its output depends on the browser’s implementation. crypto.getRandomValues fills an array with values from a cryptographically secure generator, the same kind used for encryption keys. Our Coin Flipper and Dice Roller use only the second. A coin needs one bit, so one random byte gives eight independent flips.

The Remainder Trap: Modulo Bias

The obvious way to turn a random byte (0 to 255) into a die roll is to take the remainder after dividing by 6 and add 1. That is quietly unfair, because 256 is not a multiple of 6: four faces get 43 of the 256 byte values and two faces get only 42.

MethodChance of faces 1-4Chance of faces 5-6
Random byte % 643/256 = 16.797%42/256 = 16.406%
32-bit value % 6about 16.6667% eachdiffers by about 1 in 700 million
Rejection sampling (ours)exactly 1/6exactly 1/6

The difference is small for one roll and real over thousands; with a 20-sided die and a byte, some faces come up 13/256 (5.08%) of the time and others 12/256 (4.69%). Larger random values shrink the bias without removing it. Rejection sampling removes it: draw a 32-bit value, and if it lands in the leftover slice at the top (values that would favor some faces) throw it away and draw again. For a d7 that happens about once in a billion draws, so it costs nothing.

Streaks Are Normal

People expect a fair coin to alternate more than it does. In 100 flips the longest run of the same side is most often 6 or 7, and the chances are higher than intuition suggests:

FlipsLongest streak ofChance
1007 or more54%
10010 or more8.7%
1,00010 or more62%
1,00015 or more3.0%

While testing the coin flipper, one of our 1,000-flip batches produced 18 tails in a row, a roughly 0.4% event. It looked broken; it was not. Two million more flips in the same browser matched every expected statistic.

The Gambler’s Fallacy

After five heads, tails is not “due”. Each flip is independent, so the next one is still 50/50. We checked this directly on 10 million flips: the four pairs HH, HT, TH and TT each appeared a quarter of the time, so knowing one flip told us nothing about the next.

Dice Odds Worth Knowing

Dice totals are not equally likely even when each die is fair. Three six-sided dice total 10 with probability 1/8 but 3 or 18 with 1/216 each. Rolling four dice and dropping the lowest (written 4d6kh3) averages 12.2446 instead of 10.5. Rolling two twenty-sided dice and keeping the higher, which tabletop games call advantage, raises the chance of 15 or more from 30% to 51%. The Dice Roller computes the exact odds for any expression you type.

Are Real Coins Fair?

Heads and tails, yes; starting side, not quite. In a preregistered study of 350,757 tosses by 48 people, Bartoš and colleagues found coins landed on the side they started 50.8% of the time, as a physics model by Diaconis and colleagues had predicted, while heads came up 50.0% overall. A digital flip has no starting side.

How We Checked

All figures here come from tests on the tools’ own code: 10 million coin flips and 600,000 rolls per die type checked with chi-square tests, dice distributions compared with exact enumeration in Python, and streak probabilities calculated exactly. A deliberately broken version of each tool failed those tests.

Flip or roll

Fair coin flips and dice with exact odds.

Open Coin Flipper →

Frequently Asked Questions

Is Math.random good enough for a coin flip?
For casual use it works, but it is not designed to be unpredictable; crypto.getRandomValues is the browser’s cryptographically secure source and is what our tools use.
What is modulo bias?
Taking a random number’s remainder when the range does not divide evenly: a byte % 6 gives faces 1-4 a 43/256 chance and faces 5-6 only 42/256.
How long a streak is normal in 100 coin flips?
A run of 7 or more of the same side happens 54% of the time; 10 or more about 8.7%.
After several heads, is tails more likely?
No. Each flip is independent; in 10 million test flips every pair of consecutive results appeared equally often.
What does advantage do to a d20 roll?
Rolling two d20s and keeping the higher raises the chance of 15 or more from 30% to 51%.

Published Oct 14, 2026 by Derek Giordano

📚 References & Further Reading
Browse all utility tools →
⚡Coin Flipper→⚡Dice Roller→
UtilityComplete Guide to Barcode Types & When to Use Each→UtilityHow to Design Professional Business Cards for Free→GuideHow Fancy Text Works (And When Not to Use It)→DeveloperHow to Convert Between Binary, Octal, Decimal, and Hex→DeveloperHow to Create a Markdown Table (Syntax & Generator)→ColorHow to Generate a Color Palette from Scratch→ColorHow to Generate Shades and Tints of Any Color→ImageHow to Generate a Favicon for Your Website→