The core formula to generate random numbers in Excel is =RAND() for a decimal between 0 and 1, or =RANDBETWEEN(bottom, top) for a whole number within a range you specify. For example, =RANDBETWEEN(1, 100) returns an integer from 1 to 100, and =RAND()*100 returns a decimal between 0 and 100. These functions recalculate every time the worksheet changes, which is both their power and their main limitation.
How RAND and RANDBETWEEN Work
Excel’s random functions use a pseudo-random number generator, meaning they follow a deterministic algorithm that produces a sequence of numbers that appear random. The starting point, called a seed, is derived from the system clock, so each recalculation gives a new sequence. RAND() returns a value greater than or equal to 0 and less than 1, with about 15 digits of precision. RANDBETWEEN(bottom, top) returns an integer inclusive of both endpoints, so =RANDBETWEEN(1, 6) simulates a fair die roll.
Both functions are volatile, meaning they recalculate whenever Excel performs any calculation—for example, when you edit a cell, open the workbook, or press F9 (Windows) or Cmd+= (Mac). This is useful for live simulations, but it also means the numbers change constantly, which is often not what you want for a static list.
How to Generate a Fixed List of Random Numbers
To keep the random numbers from changing, you need to convert the formulas to static values. The simplest method:
- Enter
=RAND()or=RANDBETWEEN(1, 100)in the first cell. - Drag the fill handle down or across to fill the range.
- Select the entire range of formulas.
- Press Ctrl+C (Windows) or Cmd+C (Mac) to copy.
- Right-click the selection, choose Paste Special, then select “Values” and click OK.
Alternatively, you can use the Ribbon: Home > Paste > Paste Values. This replaces the formulas with the last calculated numbers, freezing them permanently.
Using RANDARRAY for a Dynamic Array of Random Numbers
If you have Excel 365 or Excel 2021, RANDARRAY is a more powerful option. It returns an array of random numbers in one step, and it can fill multiple rows and columns. The syntax is:
=RANDARRAY(rows, [columns], [min], [max], [integer])
rows– number of rows to fill (required).columns– number of columns (optional, defaults to 1).min– smallest value (optional, defaults to 0).max– largest value (optional, defaults to 1).integer– TRUE for whole numbers, FALSE or omitted for decimals.
Example: =RANDARRAY(10, 1, 1, 100, TRUE) creates a vertical list of 10 random integers between 1 and 100. Because it’s a dynamic array, the entire spill range recalculates together, and you can still copy and paste as values to freeze them.
How to Generate Random Numbers Without Duplicates
Neither RAND nor RANDBETWEEN guarantees uniqueness. To generate a set of unique random numbers, use a helper column with RAND() and then sort, or use the SORTBY function with a random array. A common approach:
- In column A, list the numbers you want to randomize (e.g., 1 to 100 in A1:A100).
- In column B, enter
=RAND()in each row. - Select both columns and sort by column B (Data > Sort).
For a formula-based solution in Excel 365, use =SORTBY(SEQUENCE(10), RANDARRAY(10)) to get 10 random numbers from 1 to 10 in a random order, which is effectively a permutation without replacement.
Choosing Between RAND, RANDBETWEEN, and RANDARRAY
Your choice depends on your needs:
- RAND() – best for continuous decimal values, e.g., probabilities or scaling.
- RANDBETWEEN() – best for simple integer ranges, like dice or lottery numbers.
- RANDARRAY() – best when you need a large block of random numbers quickly, especially with dynamic arrays.
For most everyday tasks, RANDBETWEEN is the most intuitive because you specify the range directly. However, if you need random decimals with a custom minimum and maximum, RAND()*(max-min)+min is a classic formula. For example, =RAND()*(50-10)+10 gives a decimal between 10 and 50.
Common Problems and How to Fix Them
One frequent issue is that random numbers keep changing when you don’t want them to. As noted, paste as values to fix them. Another problem is that RANDBETWEEN returns the same number repeatedly if you copy it down without recalculation—but that’s rare. If you need a random sample from a list, combine INDEX with RANDBETWEEN: =INDEX(A2:A100, RANDBETWEEN(1, COUNTA(A2:A100))) picks a random item from a list.
If you get a #NAME? error, it’s likely because you’re using RANDARRAY in an older version of Excel. In that case, use the older functions or upgrade to Microsoft 365. Also, remember that RAND() and RANDBETWEEN() are volatile, so if you have a large workbook, they can slow down recalculation. To minimize impact, limit their use or replace with static values after generation.
Alternatives: Using Excel’s Analysis ToolPak or VBA
For more control, you can use VBA to generate random numbers. A simple macro:
Sub GenerateRandomNumbers()
Dim i As Integer
For i = 1 To 10
Cells(i, 1).Value = WorksheetFunction.RandBetween(1, 100)
Next i
End Sub
This fills A1:A10 with random integers. Remember to save a copy of your workbook before running any macro, as macros cannot be undone with Ctrl+Z. The Analysis ToolPak add-in also offers a “Random Number Generation” tool under Data > Data Analysis, which provides more distribution options (normal, binomial, etc.), but it’s less commonly used than the built-in functions.
Frequently Asked Questions
How do I make random numbers not change?
Copy the cells containing the formulas, then use Paste Special > Values. This replaces the formulas with static numbers, so they won’t recalculate.
Can I generate random numbers between 0 and 1?
Yes, =RAND() does exactly that. To get a number between 0 and 1 with more control, use =RAND() directly.
What is the difference between RAND and RANDBETWEEN?
RAND returns a decimal between 0 and 1. RANDBETWEEN returns an integer within a range you specify. Both are volatile and recalculate with every change.
How do I generate a random date in Excel?
Dates are stored as numbers, so use =RANDBETWEEN(DATE(2020,1,1), DATE(2025,12,31)) and format the cell as a date. This returns a random date between the two dates.
Does RANDARRAY work in Excel 2019?
No, RANDARRAY requires Excel 365 or Excel 2021. In older versions, use RAND or RANDBETWEEN and fill down.
Related
- Google Sheets Query Unique: How to Get Distinct Values
- Generate 4 Digit Random Number in Java
- Java Code to Generate Random Number
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- How to Highlight in Excel Using a FormulaTo highlight cells or entire rows in Excel based on a condition, select the range, then choose Home…
- Excel Not Highlighting Cells in Formula? Try These FixesExcel highlights referenced cells only while you are editing a formula: select the formula cell and press F2,…
- Excel Formula for Checking Account RegisterThe core formula for a checking account register in Excel is a running balance: =SUM($C$2:C2) (or =C2 for…
- Excel UNIQUE Formula: Return a List Without DuplicatesIn Microsoft 365, Excel 2021, or Excel 2024, use =UNIQUE(A2:A100) to return a list of distinct values from…
- Python String Functions: The Complete GuidePython string functions are built-in methods that operate on string objects to manipulate, inspect, or transform text. They…
- Excel INDEX Function: Syntax, Examples, and Common UsesYes. In the English-language version of Microsoft Excel, the function is called INDEX. It returns the value—or, in…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.