FormatterHQ

Pick a Random Integer in a Range

Set a minimum and a maximum to get a random integer in a range where both ends can come up. The page starts at 1 to 10 with Unique values ticked, ready for draw-style picks.

Loading tool…
Ready.

How to use the Random Integer Range Generator

  1. Enter the lowest value you want as Min and the highest as Max; both can be drawn.
  2. Work out the size of the range as Max − Min + 1 to know how many different results exist.
  3. Keep Unique values ticked for lottery-style draws, or untick it for dice-style rolls.
  4. Set How many and press Generate.
  5. Sort the result if you like, then copy it with the separator you need.

How to pick a random integer in a range

To pick a random integer in a range, enter the smallest acceptable value as Min and the largest as Max. Both ends are included, and every integer between them has the same chance. This page shares its engine with the Random Number Generator, which starts at 1 to 100 with repeats allowed and is the quicker option for everyday picks. Come here when the range itself is the question: which ends count, how many values it holds and how to write the same logic in code. For signed test data and duplicate behaviour, see the Random Integer Generator.

Inclusive range semantics

The number of possible results is always Max − Min + 1. The "+ 1" is where most mistakes start, so it helps to check a few cases:

  • 1 to 10 contains ten values; 0 to 10 contains eleven.
  • -5 to 5 contains eleven values, because zero is one of them.
  • 5 to 5 is a valid range of one value; asking for three numbers without Unique values returns 5 5 5.
  • Decimal bounds are rounded inward: Min rounds up and Max rounds down, so 0.5 to 3.5 means 1 to 3.
  • Min larger than Max is rejected with an error rather than swapped silently.

Dice-style and lottery-style ranges

The Unique values setting decides which kind of draw you get. Unticked, every pick is independent and repeats can occur, like rolling a die again and again. Ticked, a value that has already come up is discarded and drawn again, like pulling numbered balls out of a drum.

ScenarioMinMaxHow manyUnique values
One six-sided die161Off
Twenty-sided die, five rolls1205Off
Coin toss as 0 or 1011Off
Six numbers from 591596On
Random order of 1 to 1011010On

Real output for six unique numbers from 1 to 59, sorted ascending with a comma separator: 7, 21, 24, 25, 36, 43. With the page defaults (1 to 10, ten numbers, unique) you get every value once in random order, for example 6 7 3 8 10 5 4 9 1 2.

One common trap: picking from 2 to 12 is not the same as rolling two dice. A range makes all eleven totals equally likely, while real dice produce 7 far more often than 2 or 12. To model the sum, generate two rolls from 1 to 6 and add them.

Off-by-one pitfalls when you code a random range

Programming languages do not agree on whether the upper bound is included, so the same range needs different arguments:

// JavaScript: both ends included
Math.floor(Math.random() * (max - min + 1)) + min

// Node.js: crypto.randomInt excludes the second argument
crypto.randomInt(1, 7)          // 1 to 6

# Python
random.randint(1, 6)            # 1 to 6, stop included
random.randrange(1, 7)          # 1 to 6, stop excluded
secrets.randbelow(6) + 1        # 1 to 6, secure

// PHP: both ends included
random_int(1, 6);

Two classic bugs in hand-written JavaScript:

  • Dropping the + 1: Math.floor(Math.random() * (max - min)) + min never returns max.
  • Using Math.round: Math.round(Math.random() * (max - min)) + min includes both ends but gives each of them half the chance of the values in between.

Note that Math.random() is fine for games and simulations but is not designed for security. This page reads from crypto.getRandomValues and uses rejection sampling, so each value in the range is exactly equally likely.

Checking your own range code

A quick test catches most range bugs: draw a few thousand values from a small range and look at the extremes. Generate 5,000 values from 1 to 6 here, sort them ascending and confirm that the list starts at 1 and ends at 6. Do the same with your implementation. If the maximum never appears, the + 1 is missing; if the first and last values turn up only about half as often as the others, something is rounding instead of flooring.

Limits of the range

Each run returns 1 to 10,000 integers, and Max − Min may not exceed 9,007,199,254,740,991. With Unique values on, the count cannot be larger than the range. To draw names instead of numbers, the Random Name Picker or Shuffle Lines work on a list directly. All draws happen in your browser.

Frequently asked questions

Is the maximum included in the range?
Yes. Min and Max are both possible results. A range of 1 to 6 behaves like a six-sided die, and 0 to 9 like a single random digit.
How many different integers does a range contain?
Max − Min + 1. So 1 to 10 holds ten values, 0 to 10 holds eleven and -5 to 5 holds eleven, because zero counts too.
Why is a random pick from 2 to 12 not the same as rolling two dice?
A range gives every value the same chance, while the sum of two dice makes 7 six times as likely as 2 or 12. Generate two rolls from 1 to 6 and add them to model dice.
Why does Python's randrange never return the upper number?
randrange follows Python's range convention, where the stop value is excluded. Use random.randint(a, b) for an inclusive upper bound, or add 1 to the stop value.
What does the error about distinct values mean?
With Unique values ticked you asked for more numbers than the range holds, for example 12 from 1 to 10. Widen the range, lower the count or untick Unique values.

Last updated September 27, 2026

Related tools