DevTools Logo
All posts

Rolling Dice Expressions Like a Tabletop RPG Engine

August 28, 2026 · DevTools

dice
tabletop
random
coin-flip

Tabletop RPG dice notation looks simple — 2d6+3 means "roll two six-sided dice and add three" — but parsing it correctly means handling multiple dice groups, mixed die sizes, and signed modifiers in one string. The 3D Dice Roller & Coin Flip tool's parser splits an expression like 1d20+2d6-1 into separate dice groups (1d20, 2d6) plus a flat modifier (-1), then rolls every individual die independently rather than approximating the sum statistically.

Supported die sizes, and why they're capped

The parser recognizes standard polyhedral sizes: d4, d6, d8, d10, d12, d20, and d100 — the actual physical dice sets tabletop games ship with. An unrecognized size like d7 is silently dropped from the expression rather than producing a nonsensical roll, and each dice group is capped at 100 dice to keep a typo like 999d6 from freezing the tab.

Why each die rolls independently

Rolling 4d6 isn't the same as generating one random number scaled to a 4-24 range — the two produce different probability distributions. Four independent d6 rolls cluster toward the middle (14 is far more likely than 4 or 24), matching how physical dice actually behave and how game systems expect the math to work; a single scaled random number would be flat across the whole range. The tool rolls each die separately with secureRandomInt(1, sides) and sums the results, preserving that real distribution shape.

Coin flips and fair picks

The coin flip is the same mechanism at d2, relabeled heads/tails. For choosing between named options instead of numbers, the Decision Wheel & Picker spins a wheel over your list; for a plain random number or raffle draw, the Random Number & Raffle Picker skips the dice notation entirely.