Category: FUNCTION | Updated: 2026-11-22
[RANDBETWEEN Function] How to Generate a Random Integer Within a Specified Range
Syntax
=RANDBETWEEN(low, high)
- low: The lower bound for the generated integer (inclusive).
- high: The upper bound for the generated integer (inclusive).
Example Table
Examples of simulating a dice roll or generating random test data within a specified range.
| Use Case | Formula | Output (Example) | Explanation |
|---|---|---|---|
| Dice roll (1–6) | =RANDBETWEEN(1, 6) |
4 | Integer from 1 to 6 |
| 2-digit random number | =RANDBETWEEN(10, 99) |
73 | Integer from 10 to 99 |
| Range with negatives | =RANDBETWEEN(-5, 5) |
-2 | Integer from -5 to 5 |
Common Errors and Caveats
- #NUM! error: If the first argument (
low) is greater than the second argument (high), a#NUM!error occurs (e.g.,=RANDBETWEEN(10, 1)). - Behavior with decimal arguments: If you pass decimals as arguments,
lowis rounded up andhighis rounded down to the nearest integers. - Automatic recalculation on sheet edits: Like
RAND, the values change whenever the sheet is edited. Use “Paste values only” if you want to freeze the results.
Frequently Asked Questions
Q. Are the specified minimum and maximum values included in the RANDBETWEEN results?
A. Yes, both are included. For example, "=RANDBETWEEN(1, 10)" generates any integer from 1 to 10 with equal probability.
Q. Can I create a list of unique random integers without duplicates?
A. RANDBETWEEN alone can produce duplicate values. To avoid duplicates, a common approach is to create a list of sequential numbers, generate random decimals next to them with RAND, and sort the list by those random numbers using SORT.