To generate random numbers in Excel, use built-in functions like RAND() or RANDBETWEEN(). These functions work in all modern Excel versions (Microsoft 365, Excel 2019, 2021, and 2024) on Windows, Mac, and web. No add-ins or special setup is required—just open a new or existing workbook and enter the formula.
What You'll Need
- A copy of Excel (Microsoft 365, Excel 2019/2021/2024, or Excel for the web)
- A new or existing Excel workbook
- Basic familiarity with entering formulas (e.g., typing
=in a cell)
Step-by-Step
- Open Excel and click on the cell where you want the first random number to appear. If you need multiple numbers, decide whether you want unique values (no repeats) or if duplicates are acceptable, as this affects your method.
- For a decimal between 0 and 1, type
=RAND()and press Enter. This returns a random decimal (e.g., 0.372841). The value updates every time the sheet recalculates (e.g., when you edit another cell or press F9). - For a whole number within a range, use
=RANDBETWEEN(bottom, top). For example, to generate a random integer between 1 and 100, type=RANDBETWEEN(1,100)and press Enter. This returns values like 42 or 7. Note: bothbottomandtopmust be integers, andbottommust be less than or equal totop. - Generate multiple random numbers by dragging the fill handle (a small square in the bottom-right corner of the selected cell) down or across to copy the formula into adjacent cells. Each cell will produce its own independent random value.
- Freeze random values if you need them to stop changing. Select the cells with formulas, press Ctrl+C (Windows) or Cmd+C (Mac) to copy, then right-click the same range and choose Paste Special > Values (or use Alt+E+S+V on Windows after copying). This replaces formulas with static numbers.
- Generate unique random numbers without duplicates (e.g., for抽签 or lottery simulation): First, list all possible values in a column (e.g., 1 to 50 in cells A1:A50). In an adjacent column, enter
=RAND()next to each number. Sort both columns by the random column (Data > Sort > Expand the selection). Then, take the first n numbers from the original column—they will now be randomly ordered and unique.
Common Mistakes
- forgetting the parentheses: Typing
=RANDor=RANDBETWEEN(1,10)without parentheses (e.g.,=RANDBETWEEN 1 10) causes a #NAME? error. Always include()after the function name. - Using RANDBETWEEN with decimals: If you type
=RANDBETWEEN(1.5, 5.5), Excel truncates to=RANDBETWEEN(1,5), giving only integers 1–5—not 1.5, 2.5, etc. For decimals, use=RAND()*(top-bottom)+bottom(e.g.,=RAND()*4+1for 1.0 to 5.0). - Not freezing values when needed: If you copy formulas instead of pasting values, the numbers will change unexpectedly during recalculation, causing confusion in reports or analyses.
- Misunderstanding volatility: Both
RAND()andRANDBETWEEN()recalculate on any change. In large or shared workbooks, this can slow performance. Consider limiting their use or switching to manual calculation (Formulas > Calculation Options > Manual).
Tips
- Combine with other functions for flexibility. To generate a random date between Jan 1, 2024, and Dec 31, 2024, use
=RANDBETWEEN(DATE(2024,1,1),DATE(2024,12,31))and format the cell as Date. - Use named ranges for
RANDBETWEENboundaries. Name cells B1 (bottom) and B2 (top), then type=RANDBETWEEN(B1,B2)for easy updates. - For unique random letters, use
=CHAR(RANDBETWEEN(65,90))for uppercase A–Z (ASCII codes 65–90) or=CHAR(RANDBETWEEN(97,122))for lowercase a–z. - Prevent recalculation during editing: Press F9 to manually trigger one-time recalculation only when you’re ready, instead of relying on automatic updates.
- For large unique samples, use Power Query (Data > Get Data > From Other Sources > Blank Query). In the Query Editor, add a custom column with
Number.RandomBetween(1,1000), then sort and remove duplicates.
Troubleshooting
- #NAME? error: This usually means Excel doesn’t recognize the function. Verify spelling:
RAND()andRANDBETWEEN()must be exact. Check for extra spaces (e.g.,= RAND()with a leading space can cause issues). Also, ensure you’re not in a non-English locale where function names differ (e.g., French usesENT.ALEA()instead ofRANDBETWEEN()). - Numbers not updating: If your workbook uses manual calculation, press F9 to force recalculation. Go to Formulas > Calculation Options and confirm it’s set to Automatic.
- Unexpected duplicates:
RAND()andRANDBETWEEN()*intentionally* allow repeats. To force uniqueness, use the sorting method in Step 6 above or add a helper column with=RAND(), sort, and take the top n rows. - Formula disappears after pasting values: This is normal—pasting as values replaces formulas with static numbers. To keep formulas, skip pasting as values. If you need to edit later, re-enter the formula.
- Works in desktop but not web: Excel for the web supports
RAND()andRANDBETWEEN(), but some older features (like Power Query) may be limited. Use the basic formulas and avoid complex workarounds.
Frequently Asked Questions
Can I generate random numbers that don’t change every time I edit the sheet?
Yes. After generating the numbers with=RAND() or =RANDBETWEEN(), copy the cells and paste them as values (right-click > Paste Special > Values). This converts formulas to static numbers.
How do I get a random number between 10 and 50 with one decimal place (e.g., 12.3)?
Use=ROUND(RAND()*40+10,1). RAND()*40 gives 0–40, adding 10 shifts it to 10–50, and ROUND(...,1) keeps one decimal.
Why does RANDBETWEEN only give integers?
By design—RANDBETWEEN returns whole numbers only. For decimals, combine RAND() with scaling and rounding as shown in the tips section.
Can I generate unique random numbers without sorting?
In Excel 365 or 2021+, use=UNIQUE(RANDARRAY(100,1,1,50,TRUE)) to generate up to 100 unique integers between 1 and 50. If duplicates occur (due to the random nature), increase the range (e.g., 1–100) and take the first n unique values.
Do these functions work on Mac or mobile?
Yes.RAND() and work identically on Windows, Mac, and Excel for iPhone/Android. The only difference is keyboard shortcuts (e.g., Cmd instead of Ctrl on Mac).
Is there a limit to how many random numbers I can generate?
Excel can handle over 1 million rows, so you can generate thousands of random numbers in a sheet. Performance may slow if many volatile functions recalculate simultaneously—consider switching to manual calculation for large sheets.