🎲

Random Number Generator

Generate truly random numbers with custom ranges — powered by cryptographic randomness.

🎲

Set your range and press Generate.

Uses your browser's cryptographic random generator — genuinely unpredictable, with no modulo bias.

Most random number generators on the web are not random enough for anything that matters. They use `Math.random()`, which is fast and convenient and completely predictable to anyone who understands the algorithm — given enough outputs, its future values can be reconstructed. That is fine for shuffling a playlist and disqualifying for a prize draw. This generator uses `crypto.getRandomValues()`, the browser's cryptographically secure source, and it correctly handles the modulo bias problem that silently skews most naive implementations. If you are picking a winner, generating a lottery entry, or doing anything where fairness is checkable, the distinction is the entire point.

How the generator works

Set your minimum and maximum, choose how many numbers you want, and decide whether duplicates are allowed. The generator draws entropy from your browser's cryptographic random source and maps it into your range using rejection sampling — a method that discards values falling outside a clean multiple of the range rather than folding them back in. That rejection step is what preserves uniformity, and it is exactly the step that most implementations skip.

The method

Naive (biased): n = Math.floor(Math.random() * range) + min Unbiased (rejection sampling): limit = floor(2³² ÷ range) × range repeat: x = crypto random 32-bit value until x < limit n = (x mod range) + min

The bias is subtle enough that it is nearly always overlooked. If you take a 32-bit random value and apply modulo 3, the range does not divide evenly into 2³², so the first values in the range appear slightly more often than the last. For a dice roll the skew is invisible. For a lottery drawing millions of times, it is measurable and exploitable. Rejection sampling fixes it by throwing away the values that would cause the imbalance and drawing again.

What to know about randomness

  • 1`Math.random()` is not suitable for anything consequential. It is a pseudorandom generator seeded from a predictable source, and browsers make no guarantees about its quality. It has been demonstrated repeatedly that observing a handful of outputs allows reconstruction of the internal state and prediction of all future values.
  • 2True randomness looks less random than people expect. Genuine sequences contain runs — six heads in a row appears in about 1.6% of 100-flip sequences. When people fabricate "random" data by hand they avoid these clusters, which is precisely how fraud investigators detect fabricated results.
  • 3For public draws, document the process before drawing. A verifiable method — announcing the range, the timestamp, and the seed source in advance — is what makes a result defensible. "We used a random generator" is not evidence of anything; participants cannot audit a claim.
  • 4Sampling without replacement means each draw changes the odds. Picking 6 numbers from 49 without duplicates is a different probability problem from 6 independent draws. The distinction matters for lotteries and raffles, and this generator handles both correctly depending on your duplicate setting.
  • 5Dice, coins, and cards are physical randomness sources and are surprisingly good ones. A well-made die is genuinely unpredictable in a way that a poorly seeded software generator is not. Casinos still use physical shuffling for exactly this reason.

Frequently asked questions

Are these numbers truly random?

They are cryptographically secure pseudorandom, which is the strongest guarantee available in a browser. The generator draws from `crypto.getRandomValues()`, which is seeded by operating system entropy — sources like hardware timing and interrupt jitter. Unlike `Math.random()`, its outputs cannot be predicted from previous values. For any practical purpose including prize draws, this is sufficient.

What is modulo bias and why does it matter?

When you map a random value into a range that does not divide evenly into the source's size, some outcomes become slightly more likely than others. Taking a 32-bit value modulo 3 makes lower numbers appear marginally more often. It is invisible for casual use but real and measurable at scale. This generator eliminates it using rejection sampling, discarding values that would land in the uneven remainder.

Can I use this for a prize draw or giveaway?

Yes — the cryptographic source and unbiased mapping make results genuinely fair. For public accountability, announce your method beforehand: state the range, the number of winners, and the time you will draw. Fairness and demonstrable fairness are different things, and for a contested draw you need the second one, which no generator can provide on its own.

Why does the same number appear twice in a row?

Because that is what randomness does. Each draw is independent, so with duplicates allowed, repeats are expected — in 10 draws from 1 to 10, there is a roughly 65% chance of at least one duplicate, which surprises almost everyone. A generator that avoided repeats to look more random would be measurably less random. If you need unique values, turn duplicates off.

Is my data sent anywhere?

No. Generation happens entirely in your browser through the built-in cryptographic API, and no numbers, settings, or results are transmitted or stored. Disconnecting from the internet does not affect the generator, because there is no server involved at any stage.