Coin Flip and Dice Roller
Heads or tails, D6, D20, 2D6 or any custom die — animated, fair, with a roll history.
What this tool does
Replaces the physical coin or die you don't have on hand. Pick a coin (heads or tails), a single D6 or D20, two D6 (with the sum), or any custom die from 3 to 100 sides. The coin flip is a 3D CSS rotation of an actual gold-and-blue coin; dice shake briefly before settling on a value. Randomness is crypto-grade — we use crypto.getRandomValues() with rejection sampling to remove the modulo bias that Math.random() % n introduces on uneven ranges. Every result lands in a history strip showing the last ten rolls, so you can prove a contested call. Useful for tabletop games, classroom decisions, sport-fixture coin tosses, splitting bills, or settling "who has to take the bins out" without rooting through a drawer for a quarter.
How to use it
Pick a die type — coin, D6, D20, 2D6 or custom. For custom, type the side count (3 to 100). Hit the big button: the coin spins on its 3D axis or the dice shake on the spot. The result lands in the panel below with the value highlighted, and gets pushed to the history strip. Switch types and roll again — each roll is independent. The history holds the last ten rolls; older ones drop off.
How the randomness works
Naive code like Math.floor(Math.random() * sides) looks random but introduces modulo bias when sides doesn't divide 2^32 evenly — some values come up slightly more often. We avoid that by sampling a 32-bit integer from crypto.getRandomValues() and rejecting any draw above floor(2^32 / sides) * sides, then taking the rejection-free draw modulo sides. The result is mathematically uniform: a fair D7 truly produces 1-7 with equal odds. The coin animation runs a CSS rotateY across multiple half-turns plus the final 0° or 180° depending on the result; the dice use a brief shake animation before revealing the chosen face.
Die types and ranges
All types use the same unbiased crypto RNG — only the visual differs.
| Type | Range | Use |
|---|---|---|
| Coin | H or T | Coin tosses, yes/no, sport draws |
| D6 | 1–6 | Standard board games |
| 2D6 | 2–12 | RPGs, settlers, monopoly |
| D20 | 1–20 | D&D, percentile-style rolls |
| Custom | 3–100 | Custom games, statistics demos |
Frequently asked questions
Is the dice really fair?
crypto.getRandomValues() with rejection sampling, which is mathematically uniform. A D7 hits each face with exactly 1/7 probability — no "the 6 always wins" bias.
EN
PT
ES