Random Number Generator
Set a range and quantity — every number is drawn with a cryptographically secure, unbiased random source, entirely in your browser.
Unbiased randomness, not just "random enough"
This generator draws from crypto.getRandomValues(), a
cryptographically secure random source — not Math.random(),
which is fast but built for animations and games, not for anything
where the fairness of the output actually matters. Getting a
secure source is only half the job, though: turning a raw 32-bit
random value into a number within your chosen range without
introducing bias takes one more step, called
rejection sampling. The naive approach —
randomValue % range — very slightly favors the low
end of the range whenever 2³² doesn't divide evenly by that
range's size. This tool instead computes the largest multiple of
your range that fits under 2³², and discards (and re-draws) any
raw value that lands above that cutoff, so every number in range
is mapped to by exactly the same number of possible raw draws —
no exceptions, no bias, for any range you choose.
Worked example
Roll a die: min 1, max 6, so the range spans 6 numbers. 2³² is
4,294,967,296, and 4,294,967,296 ÷ 6 leaves a remainder of 4 — so
the largest multiple of 6 that fits is 4,294,967,292. Any raw draw
landing in the top 4 values (4,294,967,292 through 4,294,967,295)
is thrown away and redrawn; every other draw is reduced with
% 6 and shifted up by 1 to land on 1–6. The discard
rate here is about 0.00000009% of draws — in practice, you will
essentially never see a redraw happen, but the guarantee holds
for every range, including ones small enough that a naive modulo
would visibly skew the results.
For "Allow duplicates" unchecked — picking 6 unique numbers from 1–49, like a lottery ticket — the tool draws numbers the same unbiased way and keeps a running set, redrawing on any repeat, until it has 6 distinct values. Ask for more unique numbers than the range can supply — say, 20 uniques from a range of only 10 — and you'll see a clear error instead of a silent failure: "Can't generate 20 unique numbers between 1 and 10 — that range only has 10 numbers to pick from."
Frequently asked questions
Why crypto.getRandomValues instead of Math.random?
Math.random() is a fast, predictable pseudo-random algorithm meant for things like animations and games — it is not cryptographically secure, and in some browser engines its internal state can be reconstructed from a handful of outputs. crypto.getRandomValues() draws from the operating system's cryptographically secure random number generator, the same source used for encryption keys. For a number picker used for anything that matters — a raffle, a game, a sampling task — that's the honest source to build on, this hub's house standard for every generator it ships.
What is modulo bias, and how does rejection sampling avoid it?
The naive way to turn a random 32-bit number into, say, a die roll is `randomValue % 6`. That's biased whenever the random source's range doesn't divide evenly by your target range — some remainders end up very slightly more likely than others. With a 32-bit source (4,294,967,296 possible values) and a small range like 1–6, that bias is astronomically tiny, but it's not zero, and with smaller random sources (like a single byte, 0–255) it becomes large enough to actually skew results. Rejection sampling fixes it completely: this tool computes the largest multiple of your range that still fits in 32 bits, discards any raw draw that lands above that cutoff, and only keeps draws that map back evenly. The discard rate is minuscule (see the worked example), so it costs nothing in practice while guaranteeing exactly zero bias, for any range.
Can the same number come up more than once?
Depends on the 'Allow duplicates' checkbox. Checked (the default) means every number is drawn independently, so repeats are possible and, for small ranges, likely. Unchecked switches to sampling without replacement — the tool keeps drawing until it has that many distinct numbers, then stops. If you ask for more unique numbers than the range actually contains — say, 20 unique numbers between 1 and 10 — there aren't enough distinct values to satisfy the request, and the tool tells you so instead of hanging or silently returning fewer than you asked for.
How large a range or batch can I generate?
Min and max can be any integers, positive or negative, as long as the span between them (max − min + 1) stays under about 4.29 billion — the size of the 32-bit random source this tool draws from; that covers every realistic use case from a coin flip to a range spanning the low billions. Quantity is capped at 1,000 numbers per batch, matching this hub's other bulk generators, and is instant either way since each draw only rarely needs more than one attempt.