Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Generate Random Numbers in Excel: Step-by-Step

· 8 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Excel can generate random numbers using built-in functions, and the method you choose depends on whether you need a simple decimal, a whole number within a range, or numbers that change every time you recalculate. The core tools are the RAND, RANDBETWEEN, and RANDARRAY functions. RAND returns a decimal between 0 and 1, RANDBETWEEN returns a whole number between two values you specify, and RANDARRAY (available in Microsoft 365 and Excel 2021) creates an array of random numbers. This guide covers all three, plus how to freeze the results so they stop changing.

What You'll Need

  • A computer with Microsoft Excel installed (desktop version for Windows or Mac, or the web version at office.com). The steps for RAND and RANDBETWEEN work in all versions. RANDARRAY requires Excel 365 or Excel 2021.
  • A blank worksheet or a specific cell where you want the numbers to appear.
  • Basic familiarity with typing formulas into a cell and pressing Enter.

Step-by-Step

Method 1: Generate a Random Decimal Between 0 and 1

  1. Open Excel and click on an empty cell, for example A1.
  2. Type the formula =RAND() and press Enter. The cell will display a decimal number like 0.4521.
  3. To fill a column with random decimals, click the small square at the bottom-right corner of the cell (the fill handle) and drag it down or across. Each cell gets its own independent random value.
  4. To force new random numbers, press the F9 key on Windows or Command+Equals (=) on Mac. Every time you recalculate, all RAND cells update.

Note: RAND recalculates whenever the worksheet changes or when you press F9. If you want the numbers to stay fixed, see the "Freeze the Results" section below.

Method 2: Generate a Random Whole Number Between Two Values

  1. Decide on your lower and upper bounds. For example, to simulate rolling a six-sided die, you want numbers from 1 to 6.
  2. Click an empty cell, say B1.
  3. Type =RANDBETWEEN(1,6) and press Enter. The cell shows a whole number between 1 and 6 inclusive.
  4. Copy the formula down by dragging the fill handle. Each cell gets a different random integer.
  5. To change the range, edit the numbers inside the parentheses. For instance, =RANDBETWEEN(10,100) gives numbers from 10 to 100.

RANDBETWEEN includes both endpoints, so =RANDBETWEEN(1,2) can return 1 or 2, never anything else. If you need to exclude an endpoint, adjust the formula, such as using =RANDBETWEEN(1,5) to get 1 through 5 and then adding 1 with =RANDBETWEEN(1,5)+1 to get 2 through 6.

Method 3: Generate a List of Random Numbers (RANDARRAY for Excel 365/2021)

  1. Select the range where you want the random numbers. For example, click cell C1, then drag to select C1 through C10 for ten numbers.
  2. Type =RANDARRAY(10,1) and press Ctrl+Shift+Enter (or just Enter in newer versions that support dynamic arrays). This creates 10 rows and 1 column of random decimals.
  3. To get whole numbers, add the MIN and MAX arguments: =RANDARRAY(10,1,1,100,TRUE) returns 10 integers between 1 and 100. The TRUE argument means whole numbers; FALSE or omitting it gives decimals.
  4. If you want two columns side by side, change the second argument: =RANDARRAY(10,2,1,100,TRUE) fills 10 rows and 2 columns.
  5. If you do not have RANDARRAY, use RANDBETWEEN in each cell instead, or use the fill handle method from Method 2.

Method 4: Freeze the Numbers So They Stop Changing

By default, RAND and RANDBETWEEN recalculate every time Excel refreshes. To lock in a set of values:

  1. Generate your random numbers using any method above.
  2. Select all the cells containing the formulas.
  3. Press Ctrl+C to copy.
  4. Right-click on the same selected area, choose "Paste Special" (or "Paste Values" in some versions), and select "Values" from the options. This replaces the formulas with the current numbers.
  5. Press Enter. The cells now contain static numbers that will not change when you press F9 or edit other cells.

Alternatively, you can copy the range and paste it into a new location using the same Paste Special > Values method. This is useful if you want to keep the original formula for future recalculations.

Method 5: Random Numbers Without Duplicates (for Sampling)

  1. In column A, put a list of items or numbers you want to sample from. For example, type 1 to 20 in A1:A20.
  2. In column B, next to each item, type =RAND() and fill down to B20.
  3. Select both columns A and B, go to the Data tab, and click "Sort" (or use Sort & Filter). Sort by column B (the random numbers) in ascending or descending order.
  4. The rows are now in a random order. The first N items in column A form a random sample without replacement. For example, take the first 5 for a sample of 5.
  5. If you need to preserve the original order, copy the sorted result to a new sheet or paste as values.

Common Mistakes

  • Forgetting that RAND recalculates: Many users are surprised when their "random" list changes after they type something elsewhere. This is normal behavior. Use Paste Special > Values to freeze.
  • Using RAND when you need integers: RAND only gives decimals. For whole numbers, use RANDBETWEEN or RANDARRAY with the TRUE argument.
  • Typing RANDBETWEEN without the comma: The syntax is =RANDBETWEEN(bottom,top). A missing comma, like =RANDBETWEEN(1 10), causes a #NAME? error.
  • Entering RANDARRAY without selecting enough cells: In older Excel versions, you must select the output range first. In Excel 365, it spills automatically, so selecting extra cells can cause a #SPILL! error.
  • Copying formulas instead of values: If you copy a RAND cell and paste it elsewhere, the new cell gets a new random number. To keep the same number, paste as values.

Tips

  • To generate a random percentage between 0% and 100%, use =RAND() and format the cell as a percentage (Home tab > Number format > Percentage).
  • To create a random date between two dates, use =RANDBETWEEN(DATE(2024,1,1),DATE(2024,12,31)) and format the cell as a date.
  • For a random time, use =RAND() and format as time. The decimal represents the fraction of a 24-hour day.
  • If you need a random number that does not change when you press F9, you can turn off automatic calculation: go to Formulas > Calculation Options > Manual. Then press F9 only when you want new numbers. Remember to switch back to Automatic when done.
  • To generate a random number from a normal distribution (bell curve), use =NORM.INV(RAND(),mean,standard_dev). For example, =NORM.INV(RAND(),50,10) gives values centered around 50.
  • Use the fill handle to copy a formula across a row or down a column quickly. Double-clicking the fill handle fills down to the last adjacent cell with data.

Troubleshooting

If you see #NAME? error: This usually means you misspelled the function name. Check that you typed RAND, RANDBETWEEN, or RANDARRAY exactly. Also ensure the function is available in your Excel version. RANDARRAY is not in older versions.

If you see #VALUE! error: This happens with RANDBETWEEN if the bottom number is larger than the top. Check your arguments: =RANDBETWEEN(10,1) will error. Swap them.

If you see #SPILL! error: This occurs with RANDARRAY when the cells below or to the right are not empty. The function needs a clear area to spill into. Delete any content in the way, or select a different starting cell.

If the numbers are not changing when you press F9: Check if calculation is set to Manual. Go to Formulas > Calculation Options and select Automatic. Also, if you pasted the results as values earlier, they will never change; that is expected.

If RANDARRAY is not recognized: You are likely using Excel 2019 or earlier. Use RANDBETWEEN in each cell instead, or upgrade to Microsoft 365. The web version of Excel also supports RANDARRAY.

If you get the same number repeated everywhere: This is rare but can happen if you copied a single formula and pasted it without recalculating. Press F9 to refresh, or use Paste Special > Values to check if they are actually identical. If they are, re-enter the formula in each cell individually.

Frequently Asked Questions

Can I generate random numbers that never change?

Yes. After generating the numbers, copy the cells and use Paste Special > Values. This replaces formulas with static numbers. Alternatively, set calculation to Manual and avoid pressing F9.

What is the difference between RAND and RANDBETWEEN?

RAND returns a decimal between 0 and 1 (like 0.734). RANDBETWEEN returns a whole number between two integers you specify (like 5 or 42). Use RAND for percentages or continuous values, and RANDBETWEEN for dice rolls, IDs, or any integer range.

How do I generate a random number between 1 and 10 excluding 5?

There is no direct function for exclusions. A simple workaround is to generate a number between 1 and 9, then map it: =IF(RANDBETWEEN(1,9)>=5, RANDBETWEEN(1,9)+1, RANDBETWEEN(1,9)) is messy. Better: use =LET(x,RANDBETWEEN(1,9), IF(x>=5,x+1,x)) in Excel 365. Or just generate 1-10 and ignore 5 if it appears.

Can I make random numbers in Excel without a formula?

Not directly. Excel does not have a built-in "random fill" button. However, you can use the Data Analysis Toolpak's "Random Number Generation" feature (Data > Data Analysis > Random Number Generation), which fills a range with random numbers from various distributions. If you do not see Data Analysis, you need to enable the Analysis Toolpak add-in via File > Options > Add-ins.

Why do my random numbers change when I open the file again?

Because RAND and RANDBETWEEN recalculate on file open (unless calculation is set to Manual). This is by design. To prevent it, paste the results as values before saving.

How do I generate a random sample from a list in Excel?

Add a column of RAND() next to your list, sort by that column, and take the top N rows. This gives a random sample without replacement. For a sample with replacement (duplicates allowed), use INDEX with RANDBETWEEN: =INDEX($A$1:$A$20, RANDBETWEEN(1,20)).