Random Number Generator

Generate one or many random numbers in any range, with or without repeats — using cryptographic randomness.

1,442 views

How the Numbers Are Actually Generated

Not all "random" is equal. Math.random(), available in every browser, is a fast pseudo-random generator — deterministic under the hood and, in principle, predictable if someone knows its internal state, which makes it unsuitable for anything security-sensitive like draws with real stakes. This tool instead uses crypto.getRandomValues(), the cryptographically secure random generator built into the browser, which draws from the operating system entropy sources and is not predictable even in principle.

Having a secure random source solves only half the problem, though. Mapping a random value into a specific range (say, 1-100) naively — by taking random % 100 — introduces a subtle but real modulo bias: because the raw output range of the generator usually is not an exact multiple of 100, some remainders end up very slightly more likely than others. The bias is small, but it is real and it compounds across many draws — exactly the kind of thing that should not exist in a supposedly fair raffle.

The fix is rejection sampling: instead of forcing every raw value into range via modulo, out-of-range raw values are discarded and a new one is drawn until it fits cleanly into an exact multiple of the target range. This guarantees a truly uniform distribution — every number in the range has exactly equal probability — at the cost of occasionally needing an extra draw or two, which is imperceptible at the speeds involved.

Choose a minimum, a maximum and how many numbers are needed; tick unique to prevent repeats, which is what raffles, prize draws, sampling and games need when the same entry should not win twice. Everything runs on the local device — no number is transmitted or stored anywhere, and refreshing the page produces a completely fresh draw.

Things Worth Knowing

  • Modulo bias is invisible in a handful of draws but becomes statistically detectable over thousands — rejection sampling removes it entirely rather than just shrinking it.
  • crypto.getRandomValues() being "cryptographically secure" means its output cannot be predicted even by someone who has seen previous outputs — a property Math.random() explicitly does not have and was never designed to have.
  • The range is inclusive on both ends: a 1-10 draw can produce both 1 and 10, not just the values strictly between them.
  • For an auditable raffle, number participants 1 to N, set the range accordingly, enable unique, and take a screenshot of the result, since nothing is stored server-side after the draw.

Frequently Asked Questions

Are the numbers truly random, or just "random enough"?

They come from crypto.getRandomValues(), which draws on the cryptographic entropy source of the operating system - unpredictable in principle, not just in practice, unlike the simple Math.random() used by most casual random-number scripts.

What is modulo bias and does this tool have it?

Naively mapping a random value into a range with random % N slightly favors some numbers over others, because the raw range of the generator usually is not an exact multiple of N. This tool avoids it with rejection sampling: out-of-range raw values are discarded and redrawn until a uniform result is guaranteed.

What is rejection sampling, in plain terms?

Instead of forcing every random value into a range with a modulo operation, values that would introduce bias are simply thrown away and a new one is drawn - repeated until a value that maps perfectly evenly into the range comes up. The cost is an occasional extra draw; the benefit is a truly uniform result.

Can I use this for a prize draw?

Yes. Number the participants 1 to N, set the range accordingly, enable unique, and generate as many winners as needed. Take a screenshot for the records, since results are not stored anywhere after the draw.

Are both the minimum and maximum included in the range?

Yes - the range is inclusive on both ends. A 1-10 draw can produce both 1 and 10, exactly as it would if numbered slips were drawn from a hat.

Comments

No comments yet — be the first to write one!

Similar Tools