Jump to content

Documentation/Calc Functions/RAND

From The Document Foundation Wiki


Function name:

RAND

Category:

Mathematical

Summary:

Generates a uniformly distributed random number in the range 0 (inclusive) to 1 (exclusive).

Syntax:

RAND()

Returns:

Returns a real number in the range [0, 1).

Arguments:

None.

Additional details:

  • RAND is a volatile function that produces a new random number each time Calc recalculates. This means that Calc will update the value returned by RAND when any cell is updated by selecting Data ▸ Calculate ▸ Recalculate or pressing F9, or on any input event.
  • Use the RAND.NV function for a non-volatile equivalent.
  • To generate random numbers that never recalculate, either:
    • Copy cells containing =RAND(), and use Edit ▸ Paste Special (with All and Formulas deselected and Numbers selected).
    • Use Sheet ▸ Fill Cells ▸ Fill Random Number to fill a selected cell range with random numbers, generated in accordance with the flexible settings available through the Random Number Generator dialog.
  • To generate numbers in a range other than [0, 1), either:
    • Scale the value returned by RAND to a new range using a formula of the form =(RAND()*(b-a))+a to generate a number in the range [a, b). For example, the formula =(RAND()*20)-10 would generate random numbers in the range [-10, 10).
    • Use the RANDBETWEEN function or its non-volatile equivalent RANDBETWEEN.NV.

Examples:

Formula Description Returns
=RAND()

Generate a random number r in the range 0 ≤ r < 1. The returned value will change whenever Calc recalculates.

0.41196744494765

Related LibreOffice functions:

RAND.NV

RANDBETWEEN

RANDBETWEEN.NV

ODF standard:

Section 6.16.50, part 2

Related (or similar) Excel functions:

RAND