In this Article
This Tutorial demonstrates how to use the Excel RAND Function in Excel to calculate a random number.
RAND Function Overview
The RAND Function Calculates a random number between 0 and 1.
To use the RAND Excel Worksheet Function, select a cell and type:
(Notice how the formula inputs appear)
RAND function Syntax and inputs:
How to use the RAND Function in Excel:
The RAND function generates numbers (decimals) greater than 0 and lesser than 1.
Note: RANDARRAY is a new function in Excel 2019 onwards and replaces the RAND function. But if you don’t have the latest version or need to send the file out for people who don’t have it yet, you still can use the RAND function for backwards compatibility.
Besides generating random numbers greater than 0 and lesser than 1, RANDARRAY allows you to choose how many rows and columns to place the random numbers, choose the minimum and maximum number instead of just 0 and 1, and even choose if you want whole numbers or decimals.
If you have Excel 2007 onwards, you can use RANDBETWEEN as well. Like RANDARRAY, it allows you to choose the minimum and maximum number instead of just 0 and 1. This example below shows random numbers between 1 and 100.
Generate Whole Numbers within a Range
As mentioned, RANDARRAY and RANDBETWEEN do this easily. With RAND, you need to do it like this:
The formula is basically =RAND()*(Maximum Number – Minimum Number) + Minimum Number. And wrap it with an INT to grab the integer.
Generate Random Dates or/and Time
If you know how dates and time are stored in Excel, the logic is going to be the same as above because they are stored as numbers. Just:
Time is similar, except that it’s decimal instead of a whole number or integer. Hence, remove the INT:
To have them both together, simply add them together:
Retrieve a Random Field
If you simply need to randomize decimals, RAND is perfect by itself. Most of the time though, we want to retrieve a random field. To grab a random employee in B3:B7 for instance, you can use a RAND function to assign to each employee, and INDEX and LARGE to grab a random employee:
RAND function will randomize numbers in C3:C7. RANK compares the random number in cell C3 among C3:C7 and ranks the number in descending order. 0.0843531593276469 for instance, ranks as number 3 among C3:C7. INDEX grabs the particular row number 3 from B3:B7 and that’s Sebastian Thompson.
Press the F9 key and the RAND function will recalculate. The value of 0.180669763264754 in cell C3 is now ranked 5 among the numbers in C3:C7 and thus showing the 5th row in B3:B7 and that’s Cairo Mccall.
Do note that while it’s extremely unlikely for RAND function to generate a duplicate number, it’s still theoretically possible.
Retrieve a Random Field without Duplicates
To ensure there are no duplicates, add a COUNTIF to the formula.
In the above eg, there are two instances of 0.834312895315874. Hence, they both rank the same at 5. With the COUNTIF minus 1 added, the first rank of 0.834312895315874 would be 5 + 1 -1 (5) and the second rank of 0.834312895315874 would be 5 + 2 – 1 (6) and thus pick up different rows.
RAND Function in Google Sheets
The RAND Function works exactly the same in Google Sheets as in Excel:
Use the RAND Function to calculate a random number between 0 and 1.
Return to the List of all Functions in Excel