Smart Systems for Home

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

How to Assign Random Numbers in Excel

· 5 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

Assigning random numbers in Excel is commonly used for simulations, sampling, shuffling data, or generating test datasets. Excel provides built-in functions like RAND and RANDBETWEEN that instantly generate random values—no add-ins or macros required. Simply enter the appropriate formula in a cell, and Excel will handle the rest. The key is choosing the right function for your needs: RAND for decimals between 0 and 1, or RANDBETWEEN for whole numbers in a custom range.

What You'll Need

  • Microsoft Excel (any modern version: Excel 2010, 2013, 2016, 2019, 2021, Microsoft 365)
  • A blank or existing worksheet where you want to generate random numbers
  • Basic familiarity with entering formulas in Excel cells

Step-by-Step

  1. Open your Excel workbook and click on the worksheet where you want the random numbers to appear.
  2. Decide whether you need decimal random numbers (between 0 and 1) or whole numbers in a specific range. For decimals, use the RAND function. For whole numbers, use RANDBETWEEN.
  3. To generate a random decimal between 0 and 1, click on the first target cell (e.g., A1), type =RAND(), and press Enter. You’ll see a value like 0.723419874.
  4. To generate a random whole number within a custom range, click the target cell (e.g., B1), type =RANDBETWEEN(1,100) (replace 1 and 100 with your desired minimum and maximum), and press Enter. This will return an integer such as 42.
  5. To fill multiple cells with random numbers, enter the formula in the first cell, then drag the fill handle (a small square at the bottom-right corner of the selected cell) down or across to copy the formula into adjacent cells. Each new cell will generate its own unique random value.
  6. For a large batch, select the entire range you want (e.g., A1:A100), type your formula (e.g., =RANDBETWEEN(10,50)), and press Ctrl + Enter (Windows/Linux) or ⌘ + Enter (Mac) instead of just Enter. This applies the formula to all selected cells simultaneously.
  7. Remember: both RAND and RANDBETWEEN recalculate automatically whenever *any* change is made to the workbook (like typing in another cell or pressing Enter), so your random numbers will update constantly unless you freeze them.

Common Mistakes

  • Using RAND() when you need a fixed range of whole numbers—RAND only gives decimals between 0 and 1, which may not suit your purpose.
  • Forgetting that RANDBETWEEN requires the *first* argument to be ≤ the *second* argument. Typing =RANDBETWEEN(100,1) will return a #NUM! error.
  • Assuming random numbers won’t change. By default, Excel recalculates formulas on every edit, so your list of random numbers will shift every time you press Enter or edit a cell elsewhere.
  • Copying and pasting formulas without realizing they reference new cells, causing unexpected ranges or #REF! errors. Always double-check cell references after pasting.
  • Trying to generate random numbers without locking them when you need static values—e.g., for a raffle draw or fixed test dataset. Without freezing, the numbers won’t stay constant.

Tips

  • To freeze random numbers so they stop changing, copy the entire range, then right-click and choose Values (or Values Only) under Paste Options—this replaces formulas with static numbers.
  • To generate unique random numbers (no duplicates), combine RANDBETWEEN with other functions like INDEX and MATCH, or use the newer SORTBY and SEQUENCE functions in Microsoft 365: =UNIQUE(SORTBY(SEQUENCE(10),RANDARRAY(10))) generates 10 unique random integers from 1 to 10.
  • For more control over randomness, press F9 manually to force a full workbook recalculation (e.g., after copying static values to a new sheet).
  • To generate random decimals in a specific range (e.g., 5.0 to 15.0), use =RAND()*(max-min)+min, like =RAND()*(15-5)+5.
  • Use conditional formatting to highlight outliers in your random dataset—for example, highlight values above 90 in a 1–100 RANDBETWEEN list.
  • On Mac, ensure Preferences > Calculation > Automatic is selected if you want formulas to update live.

Troubleshooting

  • #NUM! error with RANDBETWEEN: This occurs if the minimum value is greater than the maximum (e.g., =RANDBETWEEN(50,10)). Fix it by swapping the numbers: =RANDBETWEEN(10,50).
  • No numbers appearing or formulas showing as text: Check that the cell is formatted as General or Number (right-click > Format Cells > Number tab). Also ensure you typed an equals sign (=) at the beginning—the formula won’t work if entered as text (e.g., RAND() without =).
  • Numbers updating too frequently: If you need stable results, copy the range, then use Home > Paste > Values to convert formulas to static numbers. Alternatively, change calculation to Manual via Formulas > Calculation Options > Manual (but remember to press F9 to refresh when needed).
  • Unexpected duplicates in a list: RANDBETWEEN doesn’t prevent repeats by design. To avoid duplicates, use the UNIQUE + SORTBY + SEQUENCE method mentioned in the Tips section, or use a helper column with RAND() and sort/filter for uniqueness.
  • Formula doesn’t work on shared or protected sheets: If the sheet is protected, unprotect it first (Review > Unprotect Sheet). If it’s a shared workbook, some calculation behaviors may differ—consider saving a local copy and generating numbers there first.
  • Random numbers not recalculating on Excel Online: Excel for the web recalculates less frequently. Try editing any cell or pressing F9 (if supported) to force an update. For reliability, copy and paste values after generation.

Frequently Asked Questions

Can I generate random numbers that don’t change every time I edit another cell?

Yes—after generating your random numbers with RAND or RANDBETWEEN, copy the range and use Paste Special > Values to replace formulas with static numbers. This locks the values in place.

How do I generate unique random numbers in Excel?

In Excel 365 or Excel 2021+, use =UNIQUE(SORTBY(SEQUENCE(n),RANDARRAY(n))), where n is how many unique numbers you want (e.g., =UNIQUE(SORTBY(SEQUENCE(20),RANDARRAY(20))) for 20 unique integers from 1 to 20). For older versions, generate a column of RAND(), sort the data by that column, then take the first n rows.

Can I use random numbers in a pivot table?

Yes, but only as static values. If you include a RAND() or RANDBETWEEN formula directly in your source data, the pivot table will refresh and show updated numbers each time. To keep it stable, convert the random column to values first, then create the pivot table.

What’s the difference between RAND() and RANDBETWEEN?

RAND() returns a decimal between 0 (inclusive) and 1 (exclusive), like 0.274918. RANDBETWEEN(bottom, top) returns a whole number between two integers you specify (both inclusive), like 7 in =RANDBETWEEN(1,10).

Is it possible to generate random numbers without using formulas?

No—Excel’s built-in random tools always use formulas. However, once generated, you can copy values to remove the formulas, making them static. There’s no dedicated Insert Random Numbers menu command.

Do these functions work the same on Mac and Windows?

Yes. RAND() and RANDBETWEEN() behave identically on Windows, Mac, and Excel Online. The only difference is keyboard shortcuts: Ctrl + Enter (Windows/Linux) vs. ⌘ + Enter (Mac) to apply a formula to multiple selected cells at once.