← All blog posts

Random Number Generator formula — how it actually works

WhiteUI · A plain-English guide to the Random Number Generator

Every answer on the Random Number Generator comes from one short rule and one random source. The tool takes a 32-bit value from the browser’s cryptographic random source, crypto.getRandomValues, and turns it into a whole number inside your range. The three settings, minimum, maximum and count, decide everything else, and the maths below shows how.

result = minimum + (random value mod (maximum − minimum + 1))
values in range = maximum − minimum + 1
chance for any one number = 1 ÷ (maximum − minimum + 1)

At a glance

One number in ten1 in 109 in 10Each pick: 10% chance for any single number
In the default range of 1 to 10, any single number has a 1 in 10 chance on each pick.

The range rule

The range is inclusive, which means both ends count. From 1 to 10 there are 10 − 1 + 1 = 10 whole numbers. From 0 to 10 there are 10 − 0 + 1 = 11. From 1 to 100 there are 100 − 1 + 1 = 100, and from 0 to 1,000, the widest range the tool allows, there are 1,000 − 0 + 1 = 1,001. The count of values is the range size, and it is also the denominator of the chance: 1 divided by the range size.

The chance for any one number

Because every value in the range is equally likely, the chance for any single number is 1 divided by the range size. In the default range of 1 to 10, that is 1 in 10, or 10%. For a dice roll, 1 to 6, it is 1 in 6, or 16.67%. For a raffle from 1 to 100, it is 1 in 100, or 1%. And for the widest range, 0 to 1,000, it is 1 in 1,001, or about 0.1%. A wider range makes any one number less likely, and a narrower range makes it more likely, in exact proportion.

How the random value is picked

The tool asks the browser for a fresh 32-bit random value with crypto.getRandomValues, the same cryptographic source browsers use for security features, then takes that value modulo the range size and adds the minimum. The result is always a whole number between the minimum and the maximum, inclusive. Each pick asks for a new random value, so one pick never affects the next, and pressing Generate again starts from scratch.

Worked example: the tool’s starting values

With the defaults, the minimum is 1, the maximum is 10 and the count is 5. The range size is 10 − 1 + 1 = 10, so each number has a 1 in 10 chance. The tool picks five numbers, one at a time, each between 1 and 10: a possible set is 3, 7, 1, 10, 4. Change the count to 1 and the maximum to 6, and the range size becomes 6 − 1 + 1 = 6, so the single number has a 1 in 6 chance of being any one face.

The common mistake

People assume the tool remembers the last set and avoids repeating it, as if it were dealing cards from a deck. It is not: it draws with replacement, so every pick starts fresh and the same number can appear twice in a row. The chance of all five numbers in a default set being 7 is 1 in 100,000, which is rare, but the chance of some repeat appearing is 69.76%, which is common. Both facts come from the same rule, and both are correct at once.

Frequently asked questions

What formula does the Random Number Generator use?

Each number is the minimum plus a cryptographic random value modulo the range size, where the range size is maximum minus minimum plus 1.

How many values are in the range 0 to 1,000?

1,001 whole numbers, from 0 to 1,000 inclusive, so any one number has a 1 in 1,001 chance, or about 0.1%.

What random source does the tool use?

The browser’s cryptographic random source, crypto.getRandomValues. Each pick takes a fresh 32-bit value, so picks are independent.

Why can the same number appear twice?

Because each pick is independent and draws with replacement. With 5 picks from 10 values, 69.76% of sets contain at least one repeat.

More guides on the Random Number Generator

Try it yourself

Try the Random Number Generator — free, in your browser.

Open the Random Number Generator