Skip to content
AgileLogics

Random Integer Range Generator

Generates one or more random whole numbers between a minimum and maximum, inclusive, using rejection sampling to avoid bias.

How it works

Choose a minimum, maximum, and how many numbers, then click Generate.

How do you generate a random integer in a range?

Pick a minimum and a maximum, and every whole number from one to the other, inclusive, should be equally likely. This tool does that with up to 100 numbers per click. It draws 32-bit values from your browser's cryptographically secure random source (two of them combined into a 53-bit value when the range holds more than about 4.3 billion numbers) and throws away any value that would make some results more common than others.

Settings and output

Setting Default Notes
Minimum 1 Negative numbers work; decimals are rounded down
Maximum 100 Must be greater than or equal to the minimum
Numbers 1 Slider from 1 to 100

Results appear one per line, which pastes cleanly into a spreadsheet column or a text file. A blank Minimum or Maximum uses the default, while a typed 0 is used as 0. If the minimum is larger than the maximum you get the message "Min must be less than or equal to max." and no output.

Example: rolling dice

Set Minimum to 1, Maximum to 6 and Numbers to 10, then click Generate. You get ten lines, each a single digit from 1 to 6, for example:

3
3
4
4
3
5
1
5
3
3

That run came straight from the tool, and yes, it rolled five 3s. Real randomness is lumpier than people expect. With only six faces and ten rolls, repeats are guaranteed, and streaks like this are common. To simulate 2d6, generate two numbers per roll and add them; don't set the range to 2 to 12, because that makes 2 as likely as 7.

Modulo bias, and why this tool avoids it

The quick way to turn a random 32-bit value into a die roll is value % 6 + 1. The catch is that 2³² (4,294,967,296) isn't a multiple of 6. It leaves a remainder of 4, so faces 1 to 4 each get one more possible input than faces 5 and 6. With 32-bit inputs the skew is tiny, but with a single random byte (256 values) it's easy to see: faces 1 to 4 would come up 43 times in 256 and faces 5 and 6 only 42.

The fix is rejection sampling:

  1. Work out the largest block of 32-bit values (53-bit for very wide ranges) that divides evenly by the range size.
  2. Draw a value from crypto.getRandomValues.
  3. If it falls in the leftover tail above that block, discard it and draw again.
  4. Otherwise take the remainder and add the minimum.

Because the kept block is an exact multiple of the range size, every result has exactly the same number of raw values behind it, so the output is exactly uniform, not just close. Discards are rare for normal ranges, and even in the worst case at least half of all draws are kept, so a click never takes more than a moment.

The random source itself is the browser's CSPRNG. MDN describes it as a pseudo-random generator seeded with enough entropy to be suitable for cryptographic purposes, the same family of design that NIST SP 800-90A standardises as deterministic random bit generators.

Edge cases

What you enter What happens
Minimum or maximum 0 Used as 0
Blank minimum or maximum Falls back to 1 or 100
2.9 to 5.9 Rounded down to 2 to 5
Text such as abc Error: "Min and max must be numbers."
Range wider than 2^53 values Error: "The range is too wide..."
Minimum greater than maximum Error: "Min must be less than or equal to max."

Good uses

  • Sampling records for QA. Generate 20 row IDs between 1 and your table's highest ID and spot-check those rows.
  • Splitting test users. Assign each tester a number from 1 to 2 (or 1 to 4) for A/B or multi-variant groups.
  • Picking a page, question or seat. Anything numbered works, from audit pages to exam questions.
  • Dice and board games when the physical dice have gone missing.

When you need numbers without repeats, paste a numbered list into the random name picker, or put the list in random order with the text lines shuffler. For values with decimal places, such as prices or measurements, the random decimal generator works on the same principle. If you specifically need a prime, the random prime generator picks one uniformly from every prime in a range.

Last updated

Frequently asked questions

Are the minimum and maximum included?
Yes. With 1 and 6 you can get 1, 6 and everything between, each with the same probability, like a fair die.
Can the same number appear twice?
Yes. Every number is an independent draw, so repeats are normal. Drawing 5 numbers from 1 to 100 gives at least one repeat about 9.7% of the time. If you need unique numbers, such as a lottery-style draw, list the numbers one per line in the random name picker, which picks without repeats.
Can the range include 0 or negative numbers?
Yes. A minimum or maximum of 0 is used as 0, and negative numbers work too, so -10 to 0 gives eleven equally likely values. Only a blank field falls back to the default (1 for the minimum, 100 for the maximum). Decimals are rounded down, so 2.9 is used as 2.
Is this random enough for a prize draw?
The numbers come from the Web Crypto API's crypto.getRandomValues, a cryptographically secure generator, not Math.random. For a public draw, also record how you ran it (range, time, screenshot of the result) so participants can see the process was fair.
What is the biggest range it supports?
Up to 9,007,199,254,740,992 (2^53) possible values, with the minimum and maximum each between -9,007,199,254,740,991 and 9,007,199,254,740,991, the largest whole numbers JavaScript can hold exactly. A range of 0 to 100 trillion works instantly. Anything wider shows an error message instead of a result.