Roll a custom fair die with any number of sides from 2 to 1,000. Each click draws one uniform random integer—useful for tabletop RPGs, probability demos, and quick “pick a number” decisions.
Algorithm
Given sides = n, the tool returns R where 1 ≤ R ≤ n. Internally, rollDice(n) validates that n is an integer in [2, 1000], then computes:
R = floor(random × (n − 1 + 1)) + 1 = floor(random × n) + 1
using Math.random() in the browser. Each face in the inclusive range 1…n has equal probability 1/n on a fair run.
When to use it
Simulating d20, d100, or house-rule dice without physical tokens; teaching discrete uniform distributions; or resolving tie-breakers when you only need one integer outcome.
Limitations
Non-integer sides, values below 2, or above 1,000 return an error message instead of a roll. Math.random() is not cryptographically secure—do not use for passwords, lottery draws, or audit-grade randomness. Browser RNG quality varies; seeding and reproducibility are not supported.
Example
With 20 sides, a valid roll might return 14—any integer from 1 through 20 is equally likely.