Every dayRandom Generators

Random Number
generator.

Draw one number or thousands from any range, each value equally likely.

How it's worked out

The tool starts from every value your settings allow. From 1 to 100 there are 100 whole numbers. Decimal places set the step between values: 0 to 1 with 2 decimal places has 101 values, from 0.00 to 1.00, and each one is as likely as any other.

Your browser then supplies a raw 32-bit number from crypto.getRandomValues, its cryptographic generator. A raw number rr can be anything from 0 to 4,294,967,295. Turning it into a value takes a remainder:

value\displaystyle \text{value}=minimum+(rmodn),\displaystyle {}=\;\text{minimum} + (r \bmod n),r\displaystyle r<232−(232modn)\displaystyle {}< 2^{32} - (2^{32} \bmod n)

Here nn is how many values are possible. The condition on the right matters. For 1 to 100, 2322^{32} is not a multiple of 100: 96 raw numbers are left over at the top. If they were kept, the values 1 to 96 would each have one extra way to come up. So the tool throws away any raw number of 4,294,967,200 or more and draws again. That happens to a share of only 2.2 × 10⁻⁸ of draws, and afterwards every value is reached by exactly 42,949,672 raw numbers. It is one of the unbiased rejection methods Daniel Lemire compares in his 2019 paper on random integers in a range.

With No repeats on, the tool shuffles the list of values and takes the first ones, the Fisher-Yates method in Knuth's The Art of Computer Programming. It works like drawing balls from a bag. Skip drawn numbers keeps that bag between draws, so a number drawn earlier in your visit stays out until you clear the history. Ranges with more than 4,294,967,296 possible values (only reachable with decimals) use a 53-bit raw number built from two draws, with the same rule.

One detail about the very first number. The page is built ahead of time, and a server cannot use your browser's generator. So the number shown before the page finishes loading comes from a seeded generator (mulberry32 with seed 1), which always gives 68 for 1 to 100. As soon as the page loads, your browser replaces it with a fresh draw, and every later draw is fresh as well. The test draws on the chart work the same way.

Worked examples

A club raffle with 250 tickets

Dana sold tickets numbered 1 to 250 and has three prizes. She sets the range to 1 to 250, asks for 3 numbers and turns on No repeats, so no ticket can win twice. There are 2,573,000 possible sets of three winners, all equally likely. If she forgot No repeats, a draw of three would repeat a ticket 1.2% of the time. That is rare, but it would be awkward on the night. The history keeps the draw with its time, and the CSV gives her a record for the club minutes.

Open this example in the tool

Calling on 28 students, one at a time

Mr. Lee wants each student called once. He sets 1 to 28, one number per draw, and turns on Skip drawn numbers. In a sample run of 10 calls the numbers came up as 6, 27, 7, 4, 9, 25, 21, 24, 23, 14, and 18 students were still waiting. Without skipping, repeats come quickly: with 28 students, a repeat is more likely than not by call 7, when the chance has reached 55.8%.

Open this example in the tool

Checking that a die is fair

Roll a fair die 600 times and each face should come up about 100 times. Chance alone moves that a lot: 95% of the time a face lands between 82.1 and 117.9. A seeded run of 600 rolls from this tool gave 82, 108, 105, 109, 106, 90 for faces 1 to 6. Face 1 sits just outside its band, yet the chi-square test gives χ² = 6.3 and p = 0.28, nothing unusual. A die that gives 5, 8, 9, 8, 10 and 20 in 60 rolls is different: χ² = 13.4 and p = 0.02, which fails the 5% test.

Open this example in the tool

Reading your result

Every value in the range has the same chance. For one number from 1 to 100, that is 1 in 100. Earlier draws change nothing: the generator has no memory, so a number that just came up is as likely as any other next time.

Repeats are normal when they are allowed. Ten numbers from 1 to 100 contain at least one repeat 37.2% of the time. In a group of 23 people, two share a birthday 50.7% of the time. The Chance of a repeat card shows the same sum for your range. With No repeats, the tiles show how many different sets were possible instead: 13,983,816 for 6 numbers from 1 to 49.

The chart shows how the draws spread across the range. Bars wobble around the dashed line, and about 1 bar in 20 falls outside the shaded band by chance alone. The chi-square test sums those wobbles into one figure. A p-value under 0.05 fails the test, but a fair generator also fails it about 1 time in 20, so one failure means little. Draw again and see if it repeats.

For a long list, the average should sit near the middle of the range and the standard deviation near 29% of its width. For 1 to 100 those are 50.5 and 28.87. Small lists stray further from both.

Common mistakes

  • Leaving repeats on for a prize draw. Without No repeats, the same ticket can win twice. Turn it on whenever every number must be different.
  • Drawing again until you like the answer. Then the draw is no longer random. For a public draw, announce the range first, draw once, and keep the record.
  • Reading a streak as a pattern. Three high numbers in a row do not make a low one due. Each draw is independent; expecting a correction is the gambler's fallacy.
  • Rounding a random decimal yourself. Rounding a spreadsheet RAND() to one decimal place gives 0.0 and 1.0 only half the chance of the other values. Setting 1 decimal place here draws from 11 values, 0.0 to 1.0, with equal chances, ends included.
  • Forgetting the ends are included. A range of 1 to 10 can give 10. In spreadsheets, RANDBETWEEN(1, 10) also includes both ends, but RAND() never reaches 1.

Questions people ask

They come from your browser's cryptographic generator, which the operating system seeds from unpredictable hardware events. Strictly that is pseudorandom, but nobody can predict the next number from the earlier ones. RANDOM.ORG samples atmospheric noise instead; for a raffle or a classroom draw the two are equally fair.

Sources