Random Number Generator
Generate one or many random numbers in any range with optional unique constraint.
Written by Anil Gautam · Updated
Are the minimum and maximum included?
Yes, both ends can come up. The tool multiplies a random fraction by the maximum minus the minimum plus 1, rounds down and adds the result to the minimum, so 1 to 6 has six possible results and -10 to 10 has 21, each with a 1 in 21 chance, about 4.8%. If you enter the minimum and maximum the wrong way round, the tool swaps them, and an empty Minimum or Maximum box counts as 0. Negative numbers work. Results are always whole numbers inside your limits, so 1.5 to 3.2 gives 2 or 3, and a range with no whole number in it, such as 2.1 to 2.9, shows a message instead.
Numbers are drawn one at a time with the browser's Math.random and listed in the order drawn, without sorting. A single result appears in large type, and several appear as a row of chips. Copy puts them on the clipboard separated by a comma and a space, such as 14, 3, 87.
What does the all unique option change?
Without it, repeats are common: 10 numbers drawn from 1 to 100 contain at least one repeat about 37% of the time. With All unique ticked, any number already drawn is thrown back and drawn again until the list has enough distinct values. How many accepts up to 1,000. If the range is too small, for example 11 unique numbers from 1 to 10, an alert explains the problem and nothing new is generated.
Asking for every number in a range, such as 30 unique numbers from 1 to 30, returns 1 to 30 in a random order, which works for seating plans or speaking order. For a raffle with tickets 1 to 500 and three prizes, tick All unique and ask for 3 numbers; each ticket then has a 3 in 500 chance, 0.6%, of winning one of them. A 6-from-49 lottery-style draw has 13,983,816 possible combinations: set 1 and 49, ask for 6 and tick All unique to simulate one.
When is a different tool a better fit?
Math.random is fine for games and classroom draws. It is not designed for security, so for passwords use the Password Generator and for unique IDs the UUID / GUID Generator; both use the browser's cryptographic random source. To draw from a list of names, the Random Name Picker saves you numbering the entries, and the Dice Roller handles standard dice from d4 to d100.