belun.app Blog
RU

Virtual Dice: Fair Rolls, Probabilities, and the d20

How a browser rolls a fair die, why 7 keeps coming up on 2d6, and what the numbers behind common D&D rolls actually look like.

Polyhedral dice scattered across a wooden board game table mid-roll

Every gaming group has that one session where the d20 is simply gone. Under the couch, in the cat’s possession, nobody knows. The Dice Roller exists for that moment: pick a die from d4 to d20, set how many you need, click Roll. It works for remote sessions too, where half the table is on a video call and “just trust me, I rolled a 19” stops being funny by week three.

How a browser rolls a fair die

The obvious way to roll a d6 in code is Math.random() * 6. Most online rollers do exactly that, and for casual use it’s fine. But Math.random() is a predictable generator seeded somewhere you can’t see, and it was never designed for fairness guarantees.

This tool uses crypto.getRandomValues() instead, the same source browsers use to generate encryption keys. There’s one subtle trap left: if you take a random 32-bit number and use the remainder after dividing by 6, some faces come up slightly more often than others, because 4,294,967,296 doesn’t divide evenly by 6. It’s called modulo bias. The fix is rejection sampling: throw away the handful of values at the top of the range and draw again. The bias is tiny either way, but removing it costs three lines of code, so why keep it.

Why 7 keeps showing up on two dice

A single d6 is flat: every face has a 1-in-6 chance. Add a second die and the distribution turns into a pyramid. There are six ways to make 7 (1+6, 2+5, 3+4 and their mirrors) but only one way to make 2. So 7 appears on 16.7% of 2d6 rolls, while snake eyes shows up on 2.8%.

This is why Settlers of Catan players fight over the 6 and 8 tiles, and why a character with +5 to hit feels so much more reliable than the modifier suggests. Roll a few hundred dice in the tool and watch the average settle: for a d6 it drifts toward 3.5, for a d20 toward 10.5. Slowly, though. The first fifty rolls can look wildly unfair.

The rolls tabletop players actually make

A few numbers worth knowing if you play D&D:

  • A plain d20 check succeeds against DC 15 exactly 30% of the time with no modifier.
  • Rolling 4d6 and dropping the lowest (the standard way to generate ability scores) averages about 12.24, not 10.5. The method is generous by design.
  • An 8d6 fireball averages 28 damage, but the swing is real: anything from 8 to 48 is possible, and you’ll see totals under 20 more often than you’d like.

You can check any of these yourself. Set the count to 8, pick d6, and roll until you believe the average.

Streaks are not a broken die

Three natural 20s in a row feels like destiny. It’s a 1-in-8,000 event per specific sequence, sure, but across a four-hour session with a table of five people rolling constantly, rare things get plenty of chances to happen. The history panel in the roller keeps every roll with its individual values, so you can scroll back and confirm the dice were merely being dice.

The one thing the streak never does is change the next roll. After three 20s, the chance of a fourth is still exactly 5%.

Need a roll right now? Open the Dice Roller, pick your die, and let the browser do the honest work.

Try the tool

Dice Roller →