Excel Random Number Within Range: How to Generate It
In this article
To generate a random number within a specific range in Excel, use the RANDARRAY or RANDBETWEEN functions—both are built-in and require no add-ins. RANDARRAY offers more flexibility for multiple values and decimal precision, while RANDBETWEEN is simpler for whole numbers only. No external tools or plugins are needed; this works in Excel 2019, Microsoft 365, and Excel 2021 on Windows and Mac.
What You'll Need
- Microsoft Excel 2019 or later (including Microsoft 365)
- A worksheet where you want the random numbers to appear
- The minimum and maximum values defining your range
Step-by-Step
- Open your Excel workbook and click on the cell where you want the first random number to appear.
- Decide whether you need whole numbers only or decimals allowed. If you need whole numbers (like 1 to 100), use RANDBETWEEN. If you need decimals (like 1.5 to 99.9), use RANDARRAY.
- For whole numbers only: Type
=RANDBETWEEN(10,50)into the cell, replacing 10 with your minimum value and 50 with your maximum value. Press Enter. Excel will return a random integer between those two numbers, inclusive. - For decimal numbers: Type
=RANDARRAY(1,1,10,50,TRUE)into the cell. The first 1 means one row, the second 1 means one column, 10 is the minimum, 50 is the maximum, and TRUE means allow decimals. Press Enter. This returns a random decimal between 10 and 50. - To generate multiple random numbers at once, select a range of cells (e.g., B2:B10 for ten numbers), then type
=RANDBETWEEN(10,50)and press Ctrl+Shift+Enter (Windows) or Command+Shift+Enter (Mac). Excel will fill all selected cells with different random integers. - For multiple decimal numbers in a grid, select a range like C2:E5 (12 cells), type
=RANDARRAY(4,3,10,50,TRUE), then press Ctrl+Shift+Enter or Command+Shift+Enter. This creates a 4-row by 3-column grid of random decimals between 10 and 50. - Remember that these functions recalculate every time the worksheet changes. If you need to keep the values static, copy the cells, then right-click and choose Paste Values to replace the formulas with fixed numbers.
Common Mistakes
- Using RANDBETWEEN with decimal ranges—this function only returns integers. If you type
=RANDBETWEEN(1.5,5.5), Excel will round both values to 2 and 5, then return only whole numbers between them. - Forgetting to use Ctrl+Shift+Enter (or Command+Shift+Enter) when entering array formulas in older Excel versions. Without it, only the first cell will update, and others will show errors or duplicates.
- Confusing RAND with RANDBETWEEN. RAND generates a decimal between 0 and 1 only. To scale it to a custom range, you’d need complex math like
=RAND()*(50-10)+10, which is error-prone. Use RANDARRAY instead. - Not realizing that random numbers regenerate on every edit. If you type anything else in the sheet, press F9, or open the file again, all random values change. This is intentional but can cause confusion if you expect static results.
- Using RANDBETWEEN with a minimum higher than the maximum. If you type
=RANDBETWEEN(100,10), Excel returns a #NUM! error.
Tips
- Use RANDARRAY when you need control over decimal places. Add the
FALSEparameter to force whole numbers:=RANDARRAY(5,1,1,10,FALSE)gives five random integers from 1 to 10. - To avoid recalculating, copy the cells with random numbers and paste them as values. This locks the results permanently.
- Combine with other functions:
=RANDBETWEEN(1,100)*10gives multiples of 10 between 10 and 1000. - Use conditional formatting to highlight values outside a target range. For example, highlight numbers below 20 in a 10–50 range for visual alerts.
- If you’re using Excel for Mac and RANDARRAY doesn’t work, you may be on an older version. Use
=RANDBETWEEN(min,max)for integers or=min+RAND()*(max-min)for decimals. - For simulations or sampling, generate 100+ random numbers at once using a large range (e.g., A1:A100) with
=RANDARRAY(100,1,1,100,TRUE)to simulate real-world variation.
Troubleshooting
- If you see
#NAME?, your Excel version doesn’t support RANDARRAY. Use RANDBETWEEN for integers or=min+RAND()*(max-min)for decimals. - If you see
#NUM!, check that your minimum value is not greater than your maximum value. Correct the order and retry. - If formulas aren’t updating, go to Formulas > Calculation Options and ensure Automatic is selected. If it’s set to Manual, press F9 to recalculate.
- If you get the same number repeated across cells, you likely forgot to use Ctrl+Shift+Enter (or Command+Shift+Enter). Select the range again, click in the formula bar, and press the keyboard shortcut again.
- If Excel crashes when generating large arrays (e.g., 10,000+ values), reduce the size. Large RANDARRAY outputs can overload memory on older machines.
- If the cell displays ##### instead of a number, widen the column width. This is a display issue, not a formula error.