RANDBETWEEN
Returns a random integer between two inclusive bounds.
RANDBETWEEN evaluates both bounds, then samples an integer in [low, high].
The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.
Syntax
=RANDBETWEEN(bottom, top)
Arguments
| Argument | Type | Required | Default |
|---|---|---|---|
bottom | number | Required | — |
top | number | Required | — |
Remarks
- Bounds are coerced to numbers and truncated to integers.
- The function is volatile and may return a different integer each recalculation.
Error cases
- If
high < low, the function returns#NUM!.
Examples
Simulate a roll of a six-sided die.
Formula =RANDBETWEEN(1,6)
Expected result Integer in the requested range
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Use a range that includes negative values and zero.
Formula =RANDBETWEEN(-5,5)
Expected result Integer in the requested range
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Equal bounds leave a single possible integer.
Formula =RANDBETWEEN(5,5)
Expected result Integer in the requested range
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
The lower bound cannot exceed the upper bound.
Formula =RANDBETWEEN(6,1)
Expected result #NUM!
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Value always falls inside the requested interval
Formula =LET(n, RANDBETWEEN(1, 3), AND(n>=1, n<=3, INT(n)=n))
Expected result Logical value
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Equal bounds produce a fixed value
Formula =RANDBETWEEN(7, 7)
Expected result Integer in the requested range
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Upper bound below lower bound is invalid
Formula =RANDBETWEEN(5, 1)
Expected result #NUM!
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Related functions
FAQ
Are both bounds included in RANDBETWEEN?
Yes. RANDBETWEEN samples an integer in the closed interval [low, high].
What happens with decimal bounds like RANDBETWEEN(1.9, 4.2)?
Bounds are truncated to integers before sampling, so this behaves like RANDBETWEEN(1, 4).
Is RANDBETWEEN deterministic?
It is volatile, so results can change on recalculation, though a single evaluation context uses seeded randomness for reproducible execution.