Skip to content
MasterMath

Random Number Generator

Generates random numbers in whatever range you want, with or without repeats, using the system generator.

Numbers

—

Numbers—
How many—
Sum—
Mean—
Smallest—
Largest—

How this was worked out

    The rule

    each number is drawn with crypto.getRandomValues, discarding biased draws

    Why it works

    A computer’s random number is not random in the strict sense, but the system’s cryptographic generator — the same one used to create keys — is indistinguishable from randomness for any practical purpose, and it is what this page uses. The detail almost nobody accounts for is modulo bias: taking the remainder of a large random number by the size of the range favours the lower values whenever the range does not divide the maximum exactly. With six faces and one byte the difference reaches 1.6 per cent, small but real. Here the draws that land in the leftover zone are discarded and redrawn, which is the correct way to avoid it.

    How to do it by hand

    1. Choose the range: the first and last numbers that can come up, both included
    2. Choose how many you want and whether they can repeat
    3. Each number is drawn with the system generator
    4. If a draw lands in the zone that would introduce bias, it is discarded and redrawn

    What is worth knowing

    Without repeats, the count cannot exceed the size of the range: six numbers from 1 to 49 can be drawn, ten from 1 to 5 cannot, and the page says so rather than hanging. With decimals the no-repeats option disappears, because the chance of two numbers matching to several decimal places is effectively nil and filtering it would only complicate the draw. A warning for prize draws: if the result has to be verifiable by third parties, this is not enough; you need a public, reproducible method with a seed everyone can check afterwards.

    Frequently asked questions

    Are they genuinely random?

    They use the system’s cryptographic generator, the same one behind encryption keys. For any practical purpose they are indistinguishable from chance.

    What is modulo bias?

    Taking the remainder of a random number by the range favours the lower values. It is avoided by discarding draws that land in the leftover zone.

    Can I draw without repeats?

    Yes, as long as you ask for fewer numbers than the range holds.

    Is it good enough for a prize draw?

    For an informal one, yes. If third parties need to verify it, you need a public, reproducible method.