Random Number Generator

A browser has two sources of randomness, and they are not interchangeable. This tool uses the one backed by the operating system entropy pool, and reduces it into your range by throwing away and redrawing the values that would otherwise make low numbers slightly more common. The result is a flat distribution across the range you asked for.

1 to 1,000
0 gives whole numbers. Number mode only.
Random Number Generator — Numbers in a Range, Dice Rolls and Coin FlipsBuildFigure

What randomness this actually uses

JavaScript exposes two generators. Math.random() is a fast pseudorandom function with a small internal state; the values look flat under a histogram, but anyone who can observe enough output can work out the state and predict everything that follows. crypto.getRandomValues() draws from the operating system entropy pool through a cryptographically secure generator, and predicting it is not practical.

This page uses crypto.getRandomValues() when the browser has it and says so in the Source line under every result. If a browser is old enough to lack it, the code falls back to Math.random() and the Source line says that instead, so you always know which one produced the numbers in front of you.

Why a plain remainder would skew the range

The raw output is a 32-bit integer, so it covers 0 through 4,294,967,295. Suppose you want 1 to 100. Taking the remainder after dividing by 100 looks obvious and is wrong, because 4,294,967,296 is not a multiple of 100. The leftover 96 values at the top of the 32-bit space land on the first 96 outcomes, which end up very slightly more likely than the last four. The effect is tiny at this scale, but it is a real skew and it grows as the range gets larger relative to 232.

The fix used here is rejection sampling. The largest whole multiple of the range that fits under 232 is computed, and any draw at or above that ceiling is discarded and redrawn. Every remaining value maps onto exactly one outcome, so the distribution is flat. The cost is a small number of wasted draws, which at these ranges is unmeasurable.

No repeats, and what it is for

Tick No repeats and, for a range holding 200,000 whole numbers or fewer, the tool builds the whole range, runs a Fisher-Yates shuffle over it and takes the first values off the top. Fisher-Yates walks the array backwards and swaps each position with a uniformly chosen position at or before it; every possible ordering comes out with the same probability. Above 200,000 the array would be wasteful, so it switches to drawing and rejecting duplicates instead, which produces the same distribution by a slower route.

This is the mode for drawing six numbers from 1 to 49, assigning presentation slots, or picking rows out of a numbered list. Decimal mode ignores the no-repeat setting in practice, because collisions between two decimals are so rare that the setting has nothing to do.

Streaks are not faults

Ten flips coming up seven heads happens about 12 percent of the time. The same number appearing twice in five draws from 1 to 10 is more likely than not. A run of identical results is what independence looks like at small sample sizes; a generator that avoided repeats to feel more random would be the broken one. If you want to see the flat distribution, roll a few hundred dice and read the face percentages rather than the sequence.

The decimal mode has one edge worth knowing. Values are drawn continuously and then rounded to the number of places you asked for, so the two endpoints of the range come up about half as often as any interior value, because they each sit at the edge of a half-width rounding bucket. Where that matters, draw whole numbers and divide.

Where not to use this

This is not a source for passwords, keys, tokens, or any secret. It is not a lottery or a licensed draw. Even with a cryptographic source underneath, a number produced by a page you cannot inspect at the moment of the draw proves nothing to anyone who was not watching your screen, and a screenshot proves less than people assume. For anything where the outcome carries money, standing, or a legal obligation, use a physical draw in front of witnesses, or a published-seed procedure where the seed is committed before the draw and anyone can recompute the result afterwards.

Questions people ask

Can I use this to generate a password?

No. Use a password manager. The underlying source is cryptographically secure in modern browsers, but this page formats and displays numbers rather than producing and storing a secret safely, and anything shown on screen has already left your control.

Does it work with negative numbers?

Yes. Put a negative value in the Lowest field. If the two bounds are entered the wrong way round they are swapped and the result says so.

Why do decimal draws sometimes ignore the no-repeat setting?

They do not ignore it, but with several decimal places a collision is so improbable that the setting almost never changes anything. It stays available because at one decimal place over a narrow range it does still bite.

Is the same set reproducible?

No. There is no seed input, so every press is an independent draw. Copy the result if you need to keep it.

Related