RANDBETWEEN function
RANDBETWEEN picks a random whole number between two bounds, inclusive, like a dice roll or a random ID. It is volatile, so it changes on every recalculation.
Example
Read it as a sentence: pick random whole numbers from 1 to 6 and check that each one is between 1 and 6, which gives TRUE.
A
B
C
D
1
TRUE
2
3
Syntax
RANDBETWEEN(bottom, top)
-
bottom(required) - The smallest whole number allowed.
-
top(required) - The largest whole number allowed.
Returns: A random whole number between the bounds, inclusive.
RANDBETWEEN is volatile: Excel works it out again every time anything in the workbook changes.
What Excel actually returns
Each formula below was run in desktop Excel. The result is exactly what the cell showed, errors included.
| Formula | Excel shows | Case |
|---|---|---|
=LET(x,RANDBETWEEN(1,6),AND(x>=1,x<=6,x=INT(x))) | TRUE | In range |
=RANDBETWEEN(5,5) | 5 | Equal bounds |
=RANDBETWEEN(1.5,1.6) | 2 | Decimals 1.5,1.6 |
=LET(x,RANDBETWEEN(1.2,2.8),x=2) | TRUE | Decimals 1.2,2.8 |
=RANDBETWEEN("3","3") | 3 | Text numbers |
=RANDBETWEEN(1,100) | 58 | Raw (volatile) |
=RANDBETWEEN(6,1) | #NUM! | Bottom > top |
=RANDBETWEEN("a",2) | #VALUE! | Text |
Watch out for
- Volatile: it changes on every recalculation.
- Bottom above top returns #NUM!.
Where it works
- Excel
- RANDBETWEEN is in every version of Excel from 2007 on.
- Google Sheets
- Same name, same behaviour for everyday use.
Part of Math and trig functions. Every result on this page was measured in desktop Excel, build 16.0.20527. Last updated .