Documentation/Calc Functions/RANDBETWEEN
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
Function name:
RANDBETWEEN
Category:
Mathematical
Summary:
Generates a random integer that lies in a specified range.
Syntax:
RANDBETWEEN(Bottom; Top)
Returns:
Returns a random integer lying in the inclusive range [Bottom, Top].
Arguments:
Bottom is an integer value, or a reference to a cell containing that integer, that is the lower bound of the required range.
Top is an integer value, or a reference to the cell containing that integer, that is the upper bound of the required range.
- If either Bottom or Top is non-numeric, then RANDBETWEEN reports a #VALUE! error.
- If Bottom is greater than Top, then RANDBETWEEN reports an invalid argument error (Err:502).
- If either Bottom or Top is a non-integer value, then RANDBETWEEN rounds it away from 0 to the next integer value (positive values rounded towards +∞, negative values rounded towards -∞).
- If Bottom and Top are equal (after any rounding), then RANDBETWEEN returns their common value.
Additional details:
- RANDBETWEEN is a volatile function that produces a new random number each time Calc recalculates. This means that Calc will update the value returned by RANDBETWEEN when any cell is updated by selecting ▸ ▸ or pressing F9, or on any input event.
- Use the RANDBETWEEN.NV function for a non-volatile equivalent.
- To generate random numbers that never recalculate, either:
- Copy cells containing
=RANDBETWEEN()
, and use ▸ (with All and Formulas deselected and Numbers selected). - Use ▸ ▸ to fill a selected cell range with random numbers, generated in accordance with the flexible settings available through the Random Number Generator dialog.
- Copy cells containing
- To generate numbers in the range [0, 1), use the RAND function or its non-volatile equivalent RAND.NV.
Examples:
Formula | Description | Returns |
---|---|---|
=RANDBETWEEN(20; 30) |
Generate a random integer r in the range 20 ≤ r ≤ 30. The returned value will change whenever Calc recalculates. |
22 |
=RANDBETWEEN(D1; D2)
where cells D1 and D2 contain the numbers -10 and 10 respectively. |
Generate a random integer r in the range -10 ≤ r ≤ 10. The returned value will change whenever Calc recalculates. |
6 |
=RANDBETWEEN(−6.1; −6.1) |
Always returns -7. Negative numbers are rounded away from 0. |
−7 |
=RANDBETWEEN(9.2; 9.2) |
Always returns 10. Positive numbers are also rounded away from 0. |
10 |
Related LibreOffice functions:
ODF standard:
Related (or similar) Excel functions:
RANDBETWEEN