KKwikfig.

Random Number Generator

Generate random integers in any range, with a unique-numbers mode for draws and lotteries — sampled without bias from the browser's cryptographic source. Runs entirely in your browser — your numbers never leave this device.

Your numbers
…

Draws come from the browser's cryptographic random source (crypto.getRandomValues) with rejection sampling, so every value in the range is equally likely — never Math.random.

How it works

Each number = minimum + a uniform draw from 0 … (maximum − minimum), drawn by rejection sampling from crypto.getRandomValues | Unique mode: a partial Fisher–Yates shuffle of the whole range, taking the first entries — so the count can never exceed the number of values in the range

Set a minimum, a maximum and how many numbers you want. Every number is drawn independently and uniformly: each value in the range has exactly the same chance on every draw. The draws come from the browser's cryptographic random source — the same crypto.getRandomValues facility security code is built on — and are mapped onto the range by rejection sampling: bytes that fall outside an evenly dividing limit are discarded and redrawn, rather than wrapped around by a modulo that would quietly favour the small values. Predictable generators built on Math.random are never used here.

Unique mode exists for draws, raffles and lottery-style picks, where the same number twice would spoil the point. Instead of drawing and re-rolling duplicates, it builds the full range and runs a partial Fisher–Yates shuffle: each of the first positions is swapped with a uniformly chosen position from those remaining, and the first entries of the shuffled range are your numbers. That construction guarantees no repeats and keeps every set of numbers equally likely. It also creates the one hard rule on this page: you cannot draw more unique numbers than the range contains — asking for 6 unique numbers from 1 to 5 returns an explanation, not a fudge — because no honest sampler can satisfy it.

Two honest limits. First, 'equally likely' is a property of the method, not of any short run: five draws from 1 to 100 can perfectly well come out clustered or sequential, and a suspicious-looking run is not evidence the generator is broken — with truly random numbers, strange runs are guaranteed to happen sometimes. Second, this is a tool for games, draws, sampling and everyday choices, not a certified lottery or gambling system: regulated draws use audited hardware and witnessed procedures, and a browser tool, however sound its sampling, is not that.

Worked examples

A single-value range is deterministic

Input
Minimum = 7, Maximum = 7, Count = 3
Working
The range contains exactly one value, so every draw must be that value: minimum + a draw from 0 … 0, three times over. It is the simplest proof that the range endpoints are inclusive at both ends.
Result
7, 7, 7

Unique mode, drawing the whole range

Input
Minimum = 1, Maximum = 3, Count = 3, Unique = on
Working
The partial Fisher–Yates shuffle rearranges all three values, and taking the first three returns the whole range in some shuffled order — every value exactly once, in whichever order the shuffle produced. The set is guaranteed even though the order is not.
Result
1, 2 and 3, each exactly once, in shuffled order

Asking for more unique numbers than exist

Input
Minimum = 1, Maximum = 5, Count = 6, Unique = on
Working
The range holds only five different values, so a sixth unique number does not exist. The generator refuses with an explanation naming the range size, rather than silently repeating a number and calling the result unique.
Result
Error — cannot draw 6 unique numbers from a range of only 5 values

Frequently asked questions

Are the endpoints included?

Yes, both of them. A range of 1 to 100 can produce 1 and can produce 100, each with the same probability as any other single value — 1 in 100 on every independent draw. The single-value example above makes the point at the extreme: a range of 7 to 7 produces only 7s.

Why did I get the same number twice?

Because in the default mode every draw is independent, and independence allows repeats — drawing from 1 to 10 twice gives a double one time in ten, which is exactly as it should be. If repeats would spoil your use (a raffle, a draw, a lottery pick), switch on unique mode, and remember its limit: the count cannot exceed the number of values in the range.

What is rejection sampling, and why does it matter?

Random bytes have 256 possible values, and most ranges do not divide 256 evenly. The naive shortcut — byte modulo range — would hand the leftover values to the smallest numbers, biasing them. Rejection sampling instead discards any byte at or above the largest multiple of the range size that fits in 256, and redraws. Discarding a few draws is the whole cost, and no value in the range is favoured.

Can I use this for a raffle or giveaway?

For an informal draw among friends, a class or a small community, yes — the sampling is unbiased and the unique mode fits raffles directly. For anything regulated, high-value or likely to be disputed, use a witnessed, audited draw instead: this page can show its method, but it cannot produce the independent evidence a formal draw requires.

How many numbers can I generate at once?

Up to 10,000 per run in the default mode. In unique mode the limit is the range itself: a range of 1 to 100 can supply at most 100 unique numbers, because the shuffle is built from the range. Very wide unique ranges are also slower for the same reason — the range is materialised before it is shuffled.

Why not just use Math.random?

Because its outputs can be predicted from a sample of earlier outputs, which disqualifies it anywhere fairness or secrecy matters, and because the language specification leaves its algorithm to each browser. crypto.getRandomValues is the browser's cryptographic source with no such prediction property, and the rejection sampling built on it keeps the mapping onto your range even.

Related tools

More in Everyday Tools & Generators · Browse all tools