Random Number Generator

Generate one or many random numbers within any range, with an option to exclude repeats. Numbers are drawn from your browser's cryptographic random source.

Up to 1,000 at a time.

Random number

Set a range and press Generate. Numbers are drawn with the browser's cryptographic random source.

How the numbers are generated

This generator uses the Web Crypto API's getRandomValues, which draws from the operating system's cryptographically secure entropy pool rather than a simple arithmetic pseudo-random sequence. That makes the output suitable for draws, raffles, and sampling where predictability would be a problem.

It also applies rejection sampling to avoid modulo bias. Naively taking a random 32-bit integer modulo the range size makes some outcomes slightly more likely than others, because the total number of 32-bit values usually is not an exact multiple of the range. Discarding the small remainder region before taking the modulo restores an exactly uniform distribution.

Three kinds of random source
SourceHow it worksTrustTypical use
Math.random()Pseudo-random from a seedNot for anything where prediction mattersGames, simulations, shuffling a playlist
crypto.getRandomValues() (used here)Cryptographically secure; seeded from OS entropySuitable for draws, raffles, tokensAnything fair or security-sensitive
Hardware generatorSamples physical noise directlyHighest assuranceKey generation, gambling machines

True randomness versus pseudo-randomness

A pseudo-random generator produces a deterministic sequence from a starting seed. Knowing the seed and the algorithm lets you reproduce the entire sequence, which is valuable for reproducible simulations and unacceptable for anything security-sensitive. JavaScript's Math.random is such a generator and offers no guarantees about quality across browsers.

Cryptographically secure generators, like the one used here, are seeded from unpredictable physical sources such as hardware timing jitter and are designed so that observing past output does not reveal future output. Hardware generators go further, sampling physical processes like thermal noise or radioactive decay directly.

Ranges for common uses

Set the range to match what you are simulating. Every value in the range is equally likely, so the chance of any particular result is one divided by the size of the range.

Common ranges and the chance of any one value
UseRangeChance of a given value
Coin flip0 to 150%
Six-sided die1 to 616.67%
Twenty-sided die1 to 205%
Percentile1 to 1001%
Lottery ball, 1 of 491 to 492.04%
Raffle with 500 tickets1 to 5000.2%

Two dice are not uniform

One die gives every face the same chance; the sum of two does not, because there are more ways to make a 7 than a 2. To simulate two dice, generate two numbers from 1 to 6 and add them rather than one number from 2 to 12 — the second approach gets the probabilities wrong.

Probability of each total on two six-sided dice
TotalWaysProbability
21/362.78%
32/365.56%
43/368.33%
54/3611.11%
65/3613.89%
76/3616.67%
85/3613.89%
94/3611.11%
103/368.33%
112/365.56%
121/362.78%

Common uses and the no-repeat option

With repeats allowed, each draw is independent — the same number can appear more than once, exactly like rolling a die repeatedly. This is what you want for simulating independent trials.

With no repeats, the result is a random sample without replacement, which is what a raffle or lottery draw needs: once a number is picked, it cannot be picked again. This mode requires the range to be at least as large as the count, since you cannot draw ten unique values from a range of five.

Frequently asked questions

Are these numbers truly random?

They are cryptographically secure pseudo-random numbers, drawn from your operating system's entropy pool via the Web Crypto API. For any practical purpose — raffles, draws, sampling — they are unpredictable and uniformly distributed. Only specialized hardware generators sample physical randomness directly.

How do I simulate a dice roll or a coin flip?

A coin is a range of 0 to 1; a six-sided die is 1 to 6; a twenty-sided die is 1 to 20. For two dice, generate two numbers from 1 to 6 and add them — a single draw from 2 to 12 would give every total the same chance, which real dice do not.

Can I generate numbers without duplicates?

Yes. Enable the no-repeats option and every generated number will be unique. The range must contain at least as many values as you are requesting, since unique draws cannot exceed the size of the range.

Is this suitable for a raffle or giveaway?

Yes. The cryptographic random source and unbiased sampling make it appropriate for draws. Set the range to cover your entry numbers and enable no-repeats when selecting multiple distinct winners.

Why is modulo bias a problem?

Taking a random 32-bit integer modulo your range size makes lower values slightly more likely whenever the range does not divide evenly into 2³². The bias is small but real. This generator discards values in the uneven remainder region before applying the modulo, which makes the distribution exactly uniform.

Last reviewed . Results are estimates for informational purposes only.