CalcHub

Random Number Generator

This generates random integers in a range you choose, drawing from your browser's cryptographically secure random source rather than the ordinary pseudo-random generator most tools use. The distinction matters for anything where predictability would be a problem: prize draws, sampling, security-adjacent uses, or any situation where someone might have an incentive to guess the next value. A standard pseudo-random generator produces a sequence that is deterministic given its seed, and for some generators observing a handful of outputs is enough to predict the rest. The browser's crypto source draws entropy from the operating system and carries no such weakness. Set your minimum, maximum and how many numbers you need, and optionally require them to be unique — useful for draws where the same entry should not be picked twice.

How this is calculated

Values come from the Web Crypto API's getRandomValues, which fills an array with cryptographically strong random bytes supplied by the operating system's entropy pool. Those bytes are then mapped onto your chosen range.

The mapping avoids modulo bias. Naively taking a random byte modulo the range size makes the lower values slightly more likely whenever the range does not divide evenly into 256 — a small distortion, but a real one, and it is exactly the kind of flaw that matters in a draw. Rejection sampling discards values that would fall in the biased region and draws again.

Uniqueness, when requested, is enforced by tracking values already drawn and redrawing on collision. The range must be at least as large as the count, or the request is impossible to satisfy.

Cryptographic randomness versus Math.random

Math.random in a browser is fast and statistically reasonable for simulations and animations, but it is not unpredictable. Implementations use algorithms such as xorshift128+, whose internal state can be recovered from a modest number of observed outputs — after which every subsequent value is known.

For a dice roll in a game that does not matter. For a prize draw, a random sample that must withstand scrutiny, or anything where a participant benefits from predicting the outcome, it does. This generator uses the crypto source in all cases, because the performance difference is irrelevant at these volumes and the security difference is not.

What randomness does not guarantee

A genuinely random sequence will contain runs, repeats and clusters that look non-random to human intuition. Six consecutive numbers in a lottery draw are exactly as likely as any other specific combination, and a truly random ten-number draw quite often contains a repeat.

The opposite is also true: sequences that have been adjusted to look random — evenly spread, no repeats, no runs — are not random. If you need to avoid repeats for practical reasons, use the unique option rather than regenerating until the output looks right, which introduces exactly the bias you were trying to avoid.

How to use the random number generator

  1. Set the minimum and maximum. Both ends are inclusive. Any integer range works, including negative values.
  2. Choose how many numbers you need. For a unique draw, the range must contain at least as many values as you are requesting.
  3. Decide whether values must be unique. Unique for draws and sampling without replacement. Leave it off for independent rolls, where repeats are expected and correct.

Last updated: 2026-08-01

Frequently asked questions

Are these numbers truly random?

They come from crypto.getRandomValues — cryptographically strong randomness, far better than Math.random, and fine for draws, sampling and games.

Why not use Math.random?

Math.random is deterministic given its internal state, and for common implementations that state can be recovered from a modest number of observed outputs — after which every future value is predictable. Fine for animations, not for anything where someone benefits from guessing the next number.

Is this fair for a prize draw?

Yes. The values come from the operating system's entropy pool and the mapping onto your range uses rejection sampling to avoid modulo bias, which would otherwise make lower numbers marginally more likely. Turn on the unique option so no entry can be drawn twice.

Why does my random output contain repeats?

Because genuine randomness contains repeats and runs — that is what makes it random. A sequence adjusted to look evenly spread is not random. If you need distinct values, use the unique option rather than regenerating until the output looks right, which introduces bias.

Related calculators

Advertisement