Generate Random Numbers With Excel's RAND Function

Microsoft Excel logo
Wikimedia Commons

One way to generate random numbers in Excel is with the RAND function. By itself, RAND generates a limited range of random numbers, but by using it in formulas with other functions, you can expand the range of values so that:

  • RAND can be made to return random numbers within a specified range, such as 1 and 10 or 1 and 100 by specifying the high and low values of a range,
  • You can reduce the function's output to integers by combining it with the TRUNC function, which truncates or removes all decimal places from a number.

The RAND function returns an evenly distributed number greater than or equal to 0 and less than 1. While it is normal to describe the range of values generated by the function as being from 0 to 1, in reality, it is more exact to say the range is between 0 and 0.999...

These instructions apply to Excel 2019, 2016, 2013, 2010, Excel Online and Excel for Microsoft 365.

RAND Function Syntax and Arguments

Screenshot of Excel showing RAND function examples

A function's syntax refers to the layout of the function and includes the function's name, brackets, comma separators, and arguments. The syntax for the RAND function is:

=RAND()

Unlike the RANDBETWEEN function, which requires high-end and low-end arguments to be specified, the RAND function accepts no arguments.

You can see several RAND function examples in the above image.

  • The first example (row 2) enters the RAND function by itself.
  • The second example (rows 3 and 4) creates a formula that generates a random number between 1 and 10 and 1 and 100.
  • The third example (row 5) generates a random integer between 1 and 10 using the TRUNC function.
  • The last example (row 6) uses the ROUND function to reduce the number of decimal places for random numbers.

Generating Numbers With RAND

Screenshot of Excel showing RAND function 1-10 range

Again, since the RAND function takes no arguments, you can enter it by clicking on a cell and typing =RAND() which results in a random number between 0 and 1 in the cell.

Generate Numbers Within a Range

The general form of the equation used to generate a random number within a specified range is:

=RAND()*(High-Low)+Low

High and Low signify the upper and lower limits of the desired range of numbers. As an example, to generate a random number between 1 and 10 enter the following formula into a worksheet cell:

=RAND()*(10-1)+1

Generating Random Integers With RAND

Screenshot of Excel showing TRUNC and ROUND functions

To return an integer — a whole number with no decimal portion — the general form of the equation is:

=TRUNC(RAND()*(High-Low)+Low)

Rather than remove all decimal places with the TRUNC function, we can use the following ROUND function in conjunction with RAND to reduce the number of decimal places in the random number to two.

=ROUND(RAND()*(High-Low)+Low,Decimals)

RAND Function and Volatility

The RAND function is one of Excel's volatile functions; this means that:

  • The function recalculates and produces a new random number every time anyone makes a change to the worksheet, including actions such as adding new data.
  • Any formula that depends either directly or indirectly on a cell containing a volatile function also recalculates every time someone makes a change in the worksheet.
  • In worksheets or workbooks containing large amounts of data, take caution when using volatile functions because they can slow down the program's response time due to the frequency of recalculations.

You can also force the RAND function to produce new random numbers without making other changes to a worksheet by pressing the F9 key on the keyboard. This action forces the entire sheet to recalculate including any cells containing the RAND function.

You can also use the F9 key to prevent a random number from changing every time someone makes a change to the worksheet:

  1. Click on a worksheet cell where you want the random number to reside.

  2. Type the function =RAND() into the formula bar above the worksheet.

  3. Press the F9 key to change the RAND function into a static random number.

  4. Press the Enter key on the keyboard to display the random number into the selected cell.

  5. Now, pressing F9 won't affect the random number.

Was this page helpful?