This random number generator picks random whole numbers between any two values. Use it to pick a roll number, choose a winner, roll a dice, or make test data for a program.
How to use the random number picker
- Click a quick range such as 1 to 100, or type your own Minimum and Maximum.
- Enter How many numbers you want.
- Tick No repeats if every number must be different, and Sort smallest first if you want them in order.
- Click Generate.
- Copy the result, separated by commas, spaces or new lines.
Recent short results stay listed under the tool until you leave the page, so you can look back at an earlier draw.
Generate a random number between any two values
Both the minimum and maximum are included. With minimum 1 and maximum 6, each of 1, 2, 3, 4, 5 and 6 has the same 1 in 6 chance, like a real dice.
| Use | Minimum | Maximum | Count | No repeats |
|---|---|---|---|---|
| Random number 1 to 100 | 1 | 100 | 1 | Either |
| Roll a dice | 1 | 6 | 1 | Either |
| Pick 5 students from a class of 60 | 1 | 60 | 5 | Yes |
| Shuffle the order of 10 presenters | 1 | 10 | 10 | Yes |
| 4-digit number | 1000 | 9999 | 1 | Either |
| Test marks for 30 students | 0 | 100 | 30 | No |
Negative numbers work too. A range of -10 to 10 can give any whole number from -10 to 10, including 0.
Common mistake: A common mistake is asking for more unique numbers than the range holds. From 1 to 10 there are only 10 different whole numbers, so 11 numbers with No repeats is impossible. The tool tells you when this happens.
How the generator works
The tool asks your browser's crypto.getRandomValues for random bits. To turn them into a number in your range without favouring any value, it throws away the rare draws that would make some numbers more likely, a method called rejection sampling. For no-repeat draws it uses a partial Fisher-Yates shuffle, so every set of numbers is equally likely.
You can do the same in code:
| Language | Random whole number from 1 to 100 |
|---|---|
| JavaScript | Math.floor(Math.random() * 100) + 1 |
| Python | random.randint(1, 100) |
| Java | new Random().nextInt(100) + 1 |
| C | rand() % 100 + 1 (slightly biased, fine for practice) |
In Python, random.sample(range(1, 101), 6) picks 6 different numbers from 1 to 100. Note that Python's randint includes both ends, but range(1, 101) stops before 101.
Math.random and Python's random are fine for games and practice. For passwords and security tokens, use a secure source such as crypto.getRandomValues in JavaScript or Python's secrets module, as the password generator does.
Practise with random numbers
Random numbers make good test data. Generate 20 numbers from 1 to 100, paste them into a program and try:
- Finding the average and checking it against your code.
- Testing whether each number is prime.
- Playing FizzBuzz on them.
Pro tip: When testing a sorting or searching program, use No repeats for one test and allow repeats for another. Duplicate values break more programs than you would expect.
