Text & dev
Random Number Generator
Generate random numbers in any range: one number or a batch, integers or decimals, with duplicates allowed or every result unique. Unlike most generators on the web, this one does not use Math.random. It draws from the browser's Web Crypto API, the same operating-system entropy source used to create encryption keys, and maps values into your range with rejection sampling so nothing is ever biased toward the low end. That makes it fair enough for the things people actually use random numbers for: picking a giveaway winner, drawing raffle numbers, splitting a class into groups, rolling dice for a game whose set is missing, or sampling rows for a spot check. Runs entirely in your browser.
Your range
press Generate to draw
Cryptographically secure, unbiased via rejection sampling, generated on your device only.
How the random number generator works
The browser fills a buffer with random 32-bit integers from crypto.getRandomValues, which taps the operating system's entropy pool. To turn a raw 32-bit value into a number in your range, the tool uses rejection sampling: it computes the largest multiple of the range size that fits under 2³², throws away any draw at or above that ceiling, and takes the remainder of what survives. Discards are redrawn, so the loop always ends and every value in the range keeps an identical probability.
Rejection sampling
size = max − min + 1 limit = floor(2³² ÷ size) × size · redraw while draw ≥ limit result = min + (draw mod size)without the limit check, the leftover 2³² mod size values would tilt results toward the low end
Notes & assumptions
- Integer mode uses whole numbers inclusive of both ends; decimal mode returns 6 decimal places in [min, max).
- Unique mode (duplicates off) requires the count to be no larger than the range size.
- Batches are capped at 1,000 numbers per draw.
- Results are for fair picking and simulation, not a substitute for certified lottery equipment.
Settings for common draws
Most random-number jobs are one of these. Copy the row's settings into the form and generate.
| Draw | Min | Max | Count | Duplicates |
|---|---|---|---|---|
| Coin flip (1 = heads, 2 = tails) | 1 | 2 | 1 | on |
| Standard die | 1 | 6 | 1 | on |
| Two dice (sum them yourself) | 1 | 6 | 2 | on |
| D20 (tabletop games) | 1 | 20 | 1 | on |
| Percent roll | 1 | 100 | 1 | on |
| Lottery-style 6 of 49 | 1 | 49 | 6 | off |
| Pick 3 winners from 250 entrants | 1 | 250 | 3 | off |
| 4-digit code candidate | 0 | 9999 | 1 | on |
The 6-of-49 row is a nice scale check: there are 13,983,816 possible six-number combinations, which is why matching all six is a headline event. Duplicates must be off for that draw and for winner picking, since the same ball cannot leave the drum twice.
Worked example: why the modulo shortcut is biased
Suppose you want a die roll and take one random byte (0 to 255) modulo 6. The 256 possible bytes split into 42 complete groups of six with 4 bytes left over, because 256 = 42 × 6 + 4. Those leftovers map to results 0, 1, 2 and 3, which therefore occur 43 times out of 256 (16.80%) while 4 and 5 occur 42 times (16.41%). A fair die should give each face 16.67%. The skew looks small, but it is systematic, and over many draws it is detectable and exploitable.
Rejection sampling removes the leftovers instead of tolerating them: with a ceiling of 252 (the largest multiple of 6 below 256), any draw of 252 to 255 is discarded and redrawn, and the surviving values split into exactly 42 groups per face. This tool does the same arithmetic at 32-bit scale, where the discard zone for a die is just 4 values out of 4,294,967,296, so redraws are vanishingly rare and the fairness is exact.
Frequently asked questions
How does this random number generator work?
It asks your browser's Web Crypto API (crypto.getRandomValues) for random 32-bit values, then maps them into your range with rejection sampling so every number is equally likely. Nothing is sent to a server; the randomness comes from your own device's operating system.
Is this better than Math.random?
For anything that matters, yes. Math.random is a fast pseudorandom generator that is fine for animations but is not cryptographically secure, and its outputs can be predicted from previous ones in some engines. crypto.getRandomValues draws from the operating system's entropy pool, the same source used for generating keys and tokens.
What is modulo bias and does this tool avoid it?
Naively taking a random byte modulo 6 is biased: 256 values split into 42 full groups of 6 with 4 left over, so results 0 to 3 land 43 times out of 256 (16.80%) while 4 and 5 land 42 times (16.41%). This tool avoids that by rejection sampling: draws that fall in the leftover zone are thrown away and redrawn, which makes every outcome exactly equally likely.
Can I generate numbers without repeats?
Yes, turn off allow duplicates. The tool then draws without replacement, like pulling numbered balls from a drum, which is what you want for raffles, lottery-style picks and assigning people to groups. The count cannot exceed the size of the range in this mode: you cannot pick 10 unique numbers between 1 and 6.
How do I simulate dice, coins and lottery draws?
A coin is a range of 1 to 2, a standard die is 1 to 6, a d20 is 1 to 20, and a percentage roll is 1 to 100, all with duplicates allowed. A classic 6-of-49 lottery draw is min 1, max 49, count 6, duplicates off. The settings table on this page lists each one ready to copy.
Are these numbers truly random?
They are cryptographically secure random numbers: unpredictable in practice and suitable for picking winners fairly or generating codes. Philosophically true randomness requires a physical source like radioactive decay; your operating system mixes hardware noise into its entropy pool, which is as close as software gets and far stronger than a seeded formula.
Can I use this to pick a contest winner?
Yes. Number your entrants 1 through N, set the range to 1 to N, and generate with duplicates off if you are drawing several winners. Because the source is the operating system's secure generator rather than a predictable formula, no one, including you, can steer the outcome. Screenshot the result for transparency.