Skip to main content
UtilitiesFree · no sign-up

Random Number Generator

Cryptographic random numbers with rejection sampling, so no value is quietly favoured.

Updated

Both ends are included in the draw.

5 numbers

Your numbers

Set your range on the left, then press Generate to draw.

The draw uses your browser’s cryptographic random generator with rejection sampling, not a modulo. Taking a raw random number modulo the range size would make the lowest values come up slightly more often; discarding the values that would skew it keeps every number in the range equally likely.

In short

Is a random number generator actually random?

This one draws from the browser cryptographic generator, not from the ordinary random function. For a 1 to 100 draw it discards 96 of the 4,294,967,296 possible 32-bit values before taking a remainder, so each of the 100 outcomes is exactly equally likely instead of very slightly favouring the low numbers.

Cryptographically secure means unpredictable to anyone who does not control your device, which is a different claim from certified: a regulated lottery or prize draw needs an audited procedure, not a web page.

How to use the random number generator

Set the range, set how many numbers you want, choose whether repeats are allowed, and the values appear immediately. The defaults draw 5 unique numbers from 1 to 100.

Both ends of the range are inclusive, which is worth stating because it is the single most common off-by-one in this kind of tool: 1 to 100 has 100 possible values, and 0 to 99 also has 100.

A reversed range is normalised rather than refused, so entering 10 as the minimum and 1 as the maximum still draws from 1 to 10. The count is capped at 1,000 numbers per draw and the range at plus or minus one billion.

4,294,967,296

Possible 32-bit values

the source the generator draws from

96

Values discarded for 1 to 100

so all 100 outcomes are equally likely

1,000

Numbers per draw, at most

range up to plus or minus one billion

Unique mode changes what is being asked for. With repeats allowed, each number is an independent draw and duplicates are expected: pull five values from 1 to 100 and there is a real chance two of them match, exactly as there is with five rolls of a hundred-sided die.

With unique on, the tool draws without replacement, which is the lottery model, the raffle model, and the model for picking distinct winners from a list of entrant numbers. If you ask for more unique numbers than the range can supply, the tool says so rather than silently repeating or hanging, because a request for 10 unique values from a range of 5 has no answer at all.

The randomness comes from the browser cryptographic generator, which the operating system seeds from genuine physical entropy, and not from the ordinary pseudo-random function that most scripts reach for. For picking a restaurant it makes no difference. For a prize draw, a security exercise, or anything where a participant has a reason to want the outcome, the difference is the whole point, and there is no cost to using the stronger source, so the tool simply always uses it.

Do

  • Leave unique on for a raffle, a lottery, or picking distinct winners.
  • Turn unique off for dice rolls and simulations, where repeats are the point.
  • Sort the output only when you want to read it rather than use it.
  • Use an audited procedure for anything a regulator has to accept.

Don't

  • Read a duplicate in a five-number draw as a fault.
  • Ask for more unique values than the range can hold.
  • Treat a number as due because it has not appeared yet.
  • Assume both ends are exclusive, since 1 to 100 holds 100 values.

How rejection sampling behaves across range sizes. The generator produces 32-bit values, so there are 4,294,967,296 of them. The acceptance window is the largest exact multiple of your range that fits below that, everything above it is discarded and redrawn, and the final column is the head start the low values would get if the remainder were taken directly instead.

Range sizeAcceptance windowValues discardedChance a draw is redrawnModulo bias avoided
2 (a coin flip)4,294,967,2960NeverNone: 2 divides evenly
34,294,967,29511 in 4,294,967,2961 part in 1,431,655,765
6 (a die)4,294,967,29241 in 1,073,741,8241 part in 715,827,882
104,294,967,29061 in 715,827,8831 part in 429,496,729
204,294,967,280161 in 268,435,4561 part in 214,748,364
49 (lottery main ball)4,294,967,257391 in 110,127,3671 part in 87,652,393
52 (a card deck)4,294,967,248481 in 89,478,4851 part in 82,595,524
100 (the default here)4,294,967,200961 in 44,739,2431 part in 42,949,672
1,0004,294,967,0002961 in 14,510,0251 part in 4,294,967
10,0004,294,960,0007,2961 in 588,6741 part in 429,496
1,000,0004,294,000,000967,2961 in 4,4401 part in 4,294, or 0.023 percent
10,000,0004,290,000,0004,967,2961 in 8651 part in 429, or 0.233 percent
Computed July 2026 from the acceptance-window arithmetic the generator on this page actually runs: window = floor(4,294,967,296 / range) x range, discarded = 4,294,967,296 minus window. The bias column is the relative excess a plain remainder would give to the first few values, equal to one part in floor(4,294,967,296 / range). It assumes a 32-bit source; a generator with a shorter period, such as a single byte, is biased far more sharply.

Where do most generators quietly go wrong?

Converting a raw 32-bit value into a number in your range is where most generators quietly go wrong, and where this one takes the slower path. The obvious method is a remainder: take the random value modulo the size of the range. That is biased whenever the range does not divide evenly into the generator period, and it is biased in a specific direction, towards the low end.

This tool instead defines an acceptance window that is an exact multiple of your range, throws away any value above it, and draws again. The retry costs nothing measurable, and the result is a distribution with no lean in it at all.

Drawing a password instead of a number

The password generator uses the same cryptographic source and the same rejection sampling, drawing characters from a pool and reporting the entropy that produces.

Open the password generator

The formula, worked line by line

A random integer in a range is built in two steps: get a uniform random value from the hardware-backed generator, then map it into the range you asked for. The first step is a library call. The second step is where the interesting decision lives, because the obvious mapping is not uniform.

The generator hands back a 32-bit unsigned integer, uniform across 4,294,967,296 possible values. Your range is almost never a divisor of that number. Taking the remainder directly therefore spreads an unequal number of source values onto each output value, and the surplus always lands on the values at the bottom of the range.

source          = crypto.getRandomValues(Uint32Array(1))   in [0, 2^32)
range           = max - min + 1        (both ends inclusive)
window          = floor(2^32 / range) x range
draw            = redraw while source >= window; then min + (source mod range)
unique mode     = partial Fisher-Yates over a lazy map, O(count)
Rejection sampling: the discarded tailThe generator produces 2^32 values. Only the first 4,294,967,200 of them divide evenly by a range of 100, so the last 96 are drawn again rather than folded back with a modulo. For a die the tail is 4 values and invisible; for a range of 3 billion it is 30.2 percent of every draw.floor(2³² ÷ RANGE) × RANGE = KEPTa die roll, 1 to 64 values, invisiblethis tool, 1 to 10096 values, invisible1 to 3,000,000,00030.2% redrawncoral = kept, grey = drawn again; a modulo would keep the tail and skew the low valuesTHE MODULO TRAPrange100tail96 of 2³²a redraw1 in 44.7Mbiasnone
Only the values that divide evenly by the range are kept; the tail is drawn again. Invisible for a die roll, nearly a third of every draw for a range of 3 billion.
A six-sided die, worked through
Possible 32-bit values
4,294,967,296
Divided by 6 faces
715,827,882 times, remainder 4
Acceptance window
715,827,882 × 6 = 4,294,967,292
Discarded and redrawn
the top 4 source values
Chance of a redraw
4 in 4,294,967,296, roughly one in a billion

A plain remainder would map 715,827,883 source values onto each of the faces 1 to 4 and only 715,827,882 onto faces 5 and 6, a bias of about one part in 715,827,882: unmeasurable, undetectable, and still worth removing when it costs nothing.

The bias only becomes visible when the range is large relative to the source. Ask for a number between 1 and 10,000,000 and the arithmetic changes character: ten million divides into 4,294,967,296 only 429 times, leaving 4,967,296 values over.

A plain remainder would hand the first 4,967,296 values in the range a head start of one part in 429, which is 0.233 percent, and a simulation running tens of millions of draws would see it. Rejection sampling here discards those 4,967,296 source values, redraws about one time in 865, and returns a distribution with no lean.

The lesson generalises: modulo bias is invisible at n equals 6 and obvious at n equals ten million, and there is no threshold at which it becomes correct.

Unique mode uses a partial Fisher-Yates shuffle over a lazily built map rather than an array. A textbook shuffle would materialise the whole range, shuffle it, and take the first few entries, which is fine for 1 to 100 and catastrophic for 1 to 10,000,000, where it would try to allocate ten million entries to return five numbers.

Storing only the positions actually swapped makes the work proportional to how many numbers you asked for rather than to how wide the range is, so five unique values from a range of ten million come back instantly. If the request is impossible, more unique values than the range holds, the tool reports that rather than looping forever looking for an answer that does not exist.

Questions people ask