Skip to content

RANDBETWEEN

Returns a random whole number between two numbers you choose, including both ends. It changes on every recalculation.

Syntax

=RANDBETWEEN(, )

Math and trigonometry

All versions of Excel.

Try it

Edit the formula in A2 or change the inputs. The sheet recalculates as you type.

A2
A
B
C
1
Valid roll?
2
TRUE
3

A2 =LET(n,RANDBETWEEN(1,6),AND(n>=1,n<=6,n=INT(n))) returns TRUE

How RANDBETWEEN works

RANDBETWEEN returns a random whole number from bottom to top, with both ends possible. =RANDBETWEEN(1, 6) can return 1, 2, 3, 4, 5 or 6, each equally likely. It is the quickest way to simulate dice, draw a sample number or invent test data.

Volatile: the number keeps changing

Like RAND, RANDBETWEEN is volatile. It draws a new number when the workbook recalculates, which includes any edit, pressing F9, and opening the file. To keep a result, copy the cells and use Paste Special > Values. Because the output differs every time, the examples on this page check properties that always hold, such as a result lying between the limits, or fix the limits so there is only one answer.

The arguments

Both arguments are required, and both can be cell references: =RANDBETWEEN(D2, E2). If bottom equals top the answer is that number, so =RANDBETWEEN(5, 5) is always 5. If bottom is larger than top, you get #NUM!. Pass whole numbers for both limits.

Picking a random item from a list

Combine it with INDEX: =INDEX(A2:A9, RANDBETWEEN(1, ROWS(A2:A9))) returns a random name. Using ROWS rather than a fixed 8 keeps the formula right if the list grows.

Random dates and amounts

Dates are numbers, so =RANDBETWEEN(DATE(2025,1,1), DATE(2025,12,31)) returns a random date in 2025 once formatted as a date. For amounts with pence, divide: =RANDBETWEEN(1000, 5000)/100 gives 10.00 to 50.00.

RANDBETWEEN compared with other options

  • RAND gives decimals from 0 up to 1. Scaling it, as in =INT(RAND()*6)+1, does the same job as RANDBETWEEN(1, 6).
  • RANDARRAY returns many random numbers at once and can return decimals or whole numbers, in Microsoft 365.
  • Neither suits security uses such as passwords or lottery draws.

Large ranges of RANDBETWEEN cells slow a workbook down, since every cell recalculates on any change.

Arguments

bottom
The smallest whole number the result can be, such as 1. It must not be larger than top, or RANDBETWEEN returns #NUM!.
top
The largest whole number the result can be, such as 6. The result can equal top.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

A die roll, checked

A2 =LET(n,RANDBETWEEN(1,6),AND(n>=1,n<=6,n=INT(n)))

Result: TRUE

The roll is a different whole number each time, but it is always between 1 and 6. LET holds a single roll so every test sees the same number.

A2
A
B
C
1
Valid roll?
2
TRUE
3

A2 =LET(n,RANDBETWEEN(1,6),AND(n>=1,n<=6,n=INT(n))) returns TRUE

Example 2

Equal limits give a fixed answer

C2 =RANDBETWEEN(A2,B2)

Result: 5

With nothing between the limits, the only possible result is 5.

C2
A
B
C
1
Bottom
Top
Result
2
5
5
5
3

C2 =RANDBETWEEN(A2,B2) returns 5

Example 3

Bottom above top gives #NUM!

C2 =RANDBETWEEN(A2,B2)

Result: #NUM!

The limits are the wrong way round. Swap them, or wrap them in MIN and MAX.

C2
A
B
C
1
Bottom
Top
Result
2
10
1
#NUM!
3

C2 =RANDBETWEEN(A2,B2) returns #NUM!

Example 4

A random date in a year

A2 =YEAR(RANDBETWEEN(DATE(2025,1,1),DATE(2025,12,31)))

Result: 2025

Dates are whole numbers, so RANDBETWEEN picks a random day. YEAR confirms it is always in 2025.

A2
A
B
C
1
Year of random date
2
2025
3

A2 =YEAR(RANDBETWEEN(DATE(2025,1,1),DATE(2025,12,31))) returns 2025

Example 5

Pick a random name from a list

B8 =COUNTIF(A2:A6,INDEX(A2:A6,RANDBETWEEN(1,ROWS(A2:A6))))

Result: 1

INDEX returns a different name each time. COUNTIF then finds that name exactly once in the list, so the checkable result is always 1.

B8
A
B
C
1
Name
2
Aro
3
Bex
4
Cal
5
Dee
6
Eli
7
8
Picks found in list
1

B8 =COUNTIF(A2:A6,INDEX(A2:A6,RANDBETWEEN(1,ROWS(A2:A6)))) returns 1

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B2, pick a random name from A2:A6 and return how many times that name appears in the list.

Answer in B2.

B2
A
B
C
D
E
F
1
Names
Check
Low
High
Valid draw?
2
Aro
5
12
3
Bex
4
Cal
5
Dee
6
Eli
7

Common mistakes

  • RANDBETWEEN changes on every recalculation, even when you edit an unrelated cell. Paste as values to keep a result.
  • If bottom is greater than top, the result is #NUM!. When the limits come from cells, wrap them: RANDBETWEEN(MIN(a,b), MAX(a,b)).
  • Typing RANDBETWEEN twice gives two independent numbers. To use the same draw twice in one formula, store it in a LET name or a cell.
  • It returns whole numbers only. For a decimal between two values, use =low + RAND()*(high-low), or divide RANDBETWEEN by 100 for two decimals.
  • It isn't suitable for security or fair lotteries. Use it for modelling, test data and sampling.

Questions people ask

How do I generate a random number between 1 and 100?

Use `=RANDBETWEEN(1, 100)`. Both ends are possible results.

How do I stop RANDBETWEEN from changing?

Copy the cells and use Paste Special > Values. The formulas are replaced by the numbers they showed, and those numbers stay fixed.

Can RANDBETWEEN return a decimal?

No, only whole numbers. For decimals use `=RANDBETWEEN(1000, 5000)/100`, or `=low + RAND()*(high-low)`.

How do I pick a random item from a list?

Use `=INDEX(A2:A9, RANDBETWEEN(1, ROWS(A2:A9)))`. ROWS keeps it correct when the list grows.

How do I generate random dates?

Use `=RANDBETWEEN(DATE(2025,1,1), DATE(2025,12,31))` and format the cell as a date. Dates are whole numbers, so this picks a random day.

Learn RANDBETWEEN in a real sheet.

Tracks take you from the basics to modelling, one graded exercise at a time.