To create random numbers in Excel, use the =RAND() function for decimals between 0 and 1, or the =RANDBETWEEN(bottom, top) function for whole numbers within a specific range. These formulas allow you to generate sample data, pick random winners from a list, or create simulated datasets for financial and statistical modeling without manually entering every value.
What You'll Need
- A computer with Microsoft Excel installed (works in Excel 365, Excel 2021, 2019, 2016, and Excel for the Web).
- A basic understanding of how to select a cell and enter a formula.
- A clear idea of the numerical range you need (e.g., numbers between 1 and 100).
Step-by-Step
- Select your destination cell: Click on the cell where you want the random number to appear. If you need a large set of random numbers, you can select a single cell and then drag the fill handle later, or select a range of cells first if you are using the newer
RANDARRAYfunction. - Choose your random number type:
- For a decimal between 0 and 1: Type
=RAND()and press Enter. This function requires no arguments inside the parentheses. It will return a value such as 0.45231. - For a whole number between two specific values: Type
=RANDBETWEEN(bottom, top). For example, to get a number between 1 and 50, type=RANDBETWEEN(1, 50)and press Enter. - For a grid of random numbers (Excel 365/2021 only): Use
=RANDARRAY(rows, columns, min, max, whole_number). For example,=RANDARRAY(10, 5, 1, 100, TRUE)will create a table 10 rows high and 5 columns wide, with whole numbers between 1 and 100.
- For a decimal between 0 and 1: Type
- Apply the formula to multiple cells: If you used
RAND()orRANDBETWEEN(), click the small green square (the fill handle) in the bottom-right corner of the cell and drag it down or across to fill other cells with their own unique random numbers. - Convert formulas to static values: Because random functions are "volatile," they recalculate every time you change any cell in the workbook. To stop the numbers from changing, select the cells, press
Ctrl + Cto copy, right-click the selection, and choose Paste Values (the icon with "123").
Common Mistakes
One of the most frequent errors is forgetting that RANDBETWEEN is inclusive. If you set your range from 1 to 10, Excel can and will return exactly 1 or exactly 10. Users often mistakenly think it only returns numbers between those limits (2 through 9), which can lead to slight inaccuracies in probability models.
Another common mistake is leaving the formulas active. Many users generate a list of random winners for a contest and then continue editing their spreadsheet. Every time they hit Enter or save the file, the winners change. Always remember to "freeze" your data using Paste Values once the random selection process is complete.
Users also frequently confuse RAND() with RANDBETWEEN(). If you need a whole number but use =RAND(), you will get a long decimal. While you can wrap RAND() in other functions to get a whole number, RANDBETWEEN is the more direct tool for this specific task.
Tips
Generating random decimals in a custom range: If you need a random decimal between 10 and 20, RANDBETWEEN won't work because it only handles integers. Instead, use the formula =RAND() * (20 - 10) + 10. The general logic is =RAND() * (max - min) + min.
Preventing duplicates: Standard random functions can produce the same number twice. If you need a list of unique random numbers, the easiest method is to create a column of sequential numbers (1, 2, 3...), create a second column using =RAND() next to them, and then sort the entire table based on the random column. This effectively shuffles your list without any duplicates.
Using random numbers for sampling: When performing data analysis, you can use the INDEX and MATCH functions in combination with RANDBETWEEN to pull a random name or product from a pre-existing list. For example, =INDEX(A1:A100, RANDBETWEEN(1, 100)) will pick one random entry from the range A1 to A100.
Troubleshooting
The numbers keep changing: As mentioned, these are volatile functions. If you don't want them to change, you must copy the cells and Paste Values. If you want them to change only when you decide, you can go to the Formulas tab, click Calculation Options, and switch from Automatic to Manual. Note that this affects every formula in your entire workbook, not just the random ones.
The formula returns a #NAME? error: This usually happens if you are using RANDARRAY in an older version of Excel (like 2016 or 2013) that does not support dynamic arrays. If you see this error, switch to using RANDBETWEEN and drag the fill handle to populate your cells manually.
The formula returns a #NUM! error: This typically occurs with RANDBETWEEN if the bottom argument is larger than the top argument (e.g., =RANDBETWEEN(100, 1)). Ensure the smaller number always comes first in the formula.
The result is not random enough: While Excel's random functions are sufficient for most business and educational needs, they are "pseudo-random." If you are conducting high-level scientific research or cryptographic security work, Excel's built-in functions may not provide the necessary level of entropy. In those rare cases, specialized statistical software is recommended.
Frequently Asked Questions
Can I generate random dates in Excel?
Yes. Excel stores dates as serial numbers. To get a random date between two dates, enter the dates in two cells (e.g., A1 and A2) and use =RANDBETWEEN(A1, A2). Then, format the result cell as a "Date" using the Number format dropdown on the Home tab.
How do I create a random list of letters?
You can use the CHAR function. To get a random uppercase letter (A-Z), use =CHAR(RANDBETWEEN(65, 90)). The numbers 65 and 90 represent the ASCII codes for 'A' and 'Z'.
Is there a way to generate random numbers that don't repeat?
The RANDBETWEEN function can repeat numbers. To get unique numbers, the best way is to use the =SORTBY(sequence_range, RANDARRAY(rows)) formula in Excel 365, or the manual "Sort by Random Column" method described in the Tips section.
Does the RAND function work in Google Sheets?
Yes, =RAND() and =RANDBETWEEN() work identically in Google Sheets as they do in Microsoft Excel.
How do I force the random numbers to refresh?
If your calculation settings are set to Automatic, pressing the F9 key on your keyboard will force Excel to recalculate all volatile functions and generate new random numbers instantly.