Generate Random Number Excel Range: Easy Guide
In this article
To generate random numbers within a specific range in Excel, use the =RANDBETWEEN(bottom, top) formula, where "bottom" is your lowest desired number and "top" is your highest. For users with Microsoft 365 or Excel 2021, the =RANDARRAY() function is a more powerful alternative that can fill an entire range of cells with a single formula. These tools allow you to create mock data, assign random IDs, or conduct sampling without manually entering every value.
What You'll Need
- A computer with Microsoft Excel installed (any version from 2007 onwards for basic functions, Microsoft 365 for advanced arrays).
- A basic understanding of how to select cells and enter formulas.
- A defined minimum and maximum value for your random number range.
Step-by-Step
- Identify Your Range: Determine the lowest possible number (the bottom) and the highest possible number (the top) you want Excel to generate. For example, if you want a random number between 1 and 100, your bottom is 1 and your top is 100.
- Select the Target Cell: Click on the cell where you want the first random number to appear.
- Enter the RANDBETWEEN Formula: Type
=RANDBETWEEN(into the cell. - Input Your Limits: Type your bottom number, followed by a comma, and then your top number. Following our example, it would look like this:
=RANDBETWEEN(1, 100). - Complete the Formula: Close the parenthesis
)and press Enter. Excel will immediately generate a whole number between those two values. - Fill the Range: To apply this to multiple cells, click the small green square (the fill handle) in the bottom-right corner of the cell and drag it down or across the range of cells you wish to fill.
- Using RANDARRAY (Microsoft 365 Only): If you need to fill a large block of cells instantly, select one cell and type
=RANDARRAY(rows, cols, min, max, whole_number). For example, to fill 10 rows and 5 columns with whole numbers between 1 and 100, enter=RANDARRAY(10, 5, 1, 100, TRUE). Press Enter, and the entire range will populate automatically. - Freeze the Numbers: Because random functions in Excel are "volatile," they recalculate every time you change any cell in the workbook. To stop the numbers from changing, select the generated numbers, press Ctrl+C to copy them, right-click the selection, and choose Paste Values (the icon with "123").
Common Mistakes
One of the most frequent errors is forgetting that RANDBETWEEN only produces integers. If you attempt to use decimals (e.g., =RANDBETWEEN(1.5, 5.5)), Excel will truncate the numbers to the nearest whole integer, which may not be the result you intend. For decimals, you must use the RAND() function combined with a mathematical formula.
Another common mistake is failing to "freeze" the data. Users often build a complex spreadsheet based on random numbers, only to find that every time they enter a new piece of data elsewhere, all their random numbers change. This can destroy the integrity of a data set or a randomized list. Always remember to copy and paste as values once the random generation phase is complete.
Users also frequently swap the bottom and top arguments. While Excel is often smart enough to handle =RANDBETWEEN(100, 1), it is best practice to always list the smaller number first to avoid potential errors in more complex nested formulas or older versions of the software.
Tips
To generate random decimals between two numbers, use the formula =RAND() * (top - bottom) + bottom. For example, to get a decimal between 5.5 and 10.5, you would use =RAND() * (10.5 - 5.5) + 5.5. This is essential for scientific data or financial modeling where whole numbers are insufficient.
If you need a list of unique random numbers (meaning no number repeats), RANDBETWEEN is not the best tool because it allows duplicates. Instead, create a list of all possible numbers in one column, use =RAND() in the column next to it to assign a random decimal to each number, and then sort the entire table by the random decimal column. This effectively shuffles your list perfectly.
For those using Microsoft 365, the UNIQUE function can be wrapped around RANDARRAY to help filter out duplicates, although this can be tricky if the requested range is larger than the available pool of numbers. The sorting method mentioned above remains the most reliable way to ensure zero duplicates.
Troubleshooting
The numbers change every time I press Enter: This is the default behavior of volatile functions. To fix this, select the cells, copy them (Ctrl+C), right-click, and select Paste Values. This replaces the formula with the actual number generated.
I get a #NAME? error: This usually happens if you are using RANDARRAY in an older version of Excel (like 2016 or 2019) that does not support it. Switch to the RANDBETWEEN method described in the step-by-step section.
The formula isn't calculating; I just see the text: Check if the cell is formatted as "Text." Go to the Home tab, look at the Number dropdown menu, and change it to "General." After changing the format, double-click the cell and press Enter to trigger the calculation.
I'm getting a #NUM! error: This typically occurs if the bottom value is greater than the top value in some specific versions of Excel, or if the arguments provided are not valid numbers. Ensure both arguments are numeric and the first is smaller than the second.
Frequently Asked Questions
Can I generate random dates in Excel?
Yes. Since Excel stores dates as serial numbers, you can use RANDBETWEEN with two dates. Use the DATE function inside the formula, such as =RANDBETWEEN(DATE(2023,1,1), DATE(2023,12,31)), then format the resulting cell as a "Date."
How do I generate a random letter or text string?
You can use the CHAR function. For random uppercase letters (A-Z), use =CHAR(RANDBETWEEN(65, 90)). The numbers 65 and 90 correspond to the ASCII codes for A and Z.
What is the difference between RAND and RANDBETWEEN?
RAND() generates a decimal number between 0 and 1 (e.g., 0.452). RANDBETWEEN() generates a whole number between two specific limits that you define.
Can I force Excel to generate a new set of numbers?
Yes. You can press the F9 key on your keyboard to force all volatile functions in the workbook to recalculate and generate new random values.
Is there a limit to how large the range can be?
Excel can handle very large numbers, but the RANDBETWEEN function is limited by the maximum integer value Excel can process. For most practical business or data uses, this limit is far beyond what is necessary.