To generate random numbers in Excel, use =RAND() for a decimal between 0 and 1, =RANDBETWEEN(bottom, top) for whole numbers in a range, or =RANDARRAY(rows, columns) to fill many cells at once. These functions recalculate every time the worksheet changes, so if you need a static set, copy the results and paste as values. This guide covers each method, how to control the range, avoid duplicates, and fix common issues.
What You’ll Need
- Microsoft Excel 2019, 2021, or Microsoft 365 (RANDARRAY needs 365 or 2021; older versions use RAND and RANDBETWEEN).
- A blank worksheet or a specific range where you want the numbers.
- No add-ins or special settings required.
Step-by-Step
Method 1: Generate a Single Decimal (0 to 1)
- Click the cell where you want the random number, for example A1.
- Type
=RAND()and press Enter. - Excel returns a decimal like 0.7342. To get a number between 0 and 10, multiply:
=RAND()*10. For between 5 and 15, use=RAND()*10+5(the formula is=RAND()*(max-min)+min). - To round to two decimals, wrap it:
=ROUND(RAND()*10, 2).
Method 2: Generate Whole Numbers in a Range (RANDBETWEEN)
- Select a cell, say B1.
- Type
=RANDBETWEEN(1, 100)and press Enter. This gives a random integer from 1 to 100 inclusive. - Change the numbers to any range, e.g.,
=RANDBETWEEN(-50, 50)for negatives. - Drag the fill handle (small square at the cell’s bottom-right) down to fill a column, or copy and paste into other cells.
Method 3: Fill an Array of Random Numbers (RANDARRAY)
- Select the range where you want the numbers, for example C1:E5 (15 cells).
- Type
=RANDARRAY(5, 3)and press Ctrl+Shift+Enter (or just Enter in Microsoft 365, where dynamic arrays are automatic). This fills 5 rows by 3 columns with decimals between 0 and 1. - For whole numbers, add the min and max arguments:
=RANDARRAY(5, 3, 1, 100, TRUE). TheTRUEmakes it integers;FALSEor omitted gives decimals. - If you only want one column of 10 numbers, use
=RANDARRAY(10, 1, 1, 10, TRUE).
Method 4: Generate Random Dates or Times
- Dates are numbers in Excel. Use
=RANDBETWEEN(DATE(2024,1,1), DATE(2024,12,31))to get a random date in 2024. Format the cell as a date (Home > Number Format > Short Date). - For times, use
=RAND()and format as time (Home > Number Format > Time). This gives a random time between 0:00 and 23:59.
Method 5: Make the Numbers Static (Stop Recalculating)
- Select the cells containing your random formulas.
- Press Ctrl+C to copy.
- Right-click the same range, choose Paste Special (or press Ctrl+Alt+V), then select Values and click OK. This replaces formulas with the current numbers.
- Alternatively, press F9 to recalculate manually, but that only changes the values, it doesn’t freeze them.
Method 6: Avoid Duplicates (for a Unique List)
- RAND and RANDBETWEEN can produce repeats. To get unique random numbers, use
=SORTBY(SEQUENCE(10), RANDARRAY(10))in Excel 365. This creates the sequence 1–10 in random order. - For a larger range, say 1–100 without repeats, use
=SORTBY(SEQUENCE(100), RANDARRAY(100))and take the first N rows. - If you need a random sample from a list, put your list in A1:A20, then in B1 enter
=RAND()and drag down. Then sort by column B (Data > Sort) and take the top rows.
Common Mistakes
- Forgetting that RAND recalculates – every edit or F9 changes the numbers. If you need fixed values, paste as values.
- Using RANDBETWEEN with decimals – it only returns whole numbers. For decimals, use RAND or add a decimal argument in RANDARRAY.
- Wrong order in RANDARRAY – the syntax is
RANDARRAY(rows, columns, min, max, integer). Swapping rows and columns fills the wrong shape. - Not pressing Ctrl+Shift+Enter in older Excel – if you use RANDARRAY in Excel 2019, it won’t work; you need 365 or 2021. In older versions, use RAND and copy down.
- Formatting as text – if the cell is formatted as Text before entering the formula, Excel treats it as a string. Change format to General first.
Tips
- To generate a random percentage, use
=RAND()and format as percentage (Home > Number Format > Percentage). - For a random yes/no or true/false, use
=IF(RAND()>0.5, "Yes", "No")or=RANDBETWEEN(0,1)=1. - To create a random password or code, combine with CHAR:
=CHAR(RANDBETWEEN(65,90))gives a random uppercase letter (A–Z). For lowercase, use 97–122. - Use
=RANDARRAY(1, 10, 1, 100, TRUE)to get 10 random integers in a single row. - To refresh only the random numbers without changing other formulas, press F9 (Windows) or Cmd+= (Mac) – but this recalculates the whole workbook.
- For a random number that never changes when you open the file, use a static value: type a number, or use a macro (see Troubleshooting).
Troubleshooting
Numbers change every time I type something. That’s normal – RAND and RANDBETWEEN are volatile. To stop it, copy the cells and use Paste Special > Values. If you want the workbook to recalculate only when you press F9, go to Formulas > Calculation Options > Manual.
RANDARRAY returns a #VALUE! error. This happens if you’re using Excel 2019 or older, or if the range is too large. Check your version – RANDARRAY needs Microsoft 365 or Excel 2021. In older versions, use RAND and drag the fill handle.
I get the same number in every cell. That usually means you entered the formula in one cell and copied it without relative references – but RAND doesn’t have arguments, so it should differ. If you see the same value, check that the cells are not linked to a single formula. Also, if you typed =RAND() and then used the fill handle, it should vary. If not, press F9 to recalculate.
RANDBETWEEN gives a #NUM! error. The bottom argument must be less than the top. For example, =RANDBETWEEN(10, 1) fails. Swap the numbers.
I need a random number that doesn’t recalculate when I open the file. Use a static value: type a number, or use a macro. To create a macro that inserts a random number, press Alt+F11 to open VBA, insert a module, and paste this:
Sub InsertRandomNumber()
Dim rng As Range
Set rng = Selection
rng.Value = Int((100 - 1 + 1) * Rnd + 1) ' 1 to 100
End Sub
Then run it (F5). Save a copy of your workbook before running macros, because you cannot undo with Ctrl+Z. The macro writes a fixed number, not a formula.
My random dates show as numbers like 45234. That’s because the cell is formatted as General. Select the cells, press Ctrl+1 (Format Cells), choose Date, and pick a format.
Frequently Asked Questions
Can I generate random numbers without duplicates? Yes. Use =SORTBY(SEQUENCE(10), RANDARRAY(10)) in Excel 365/2021 to shuffle a sequence. For older versions, add a helper column with RAND and sort by it.
How do I generate a random number between 0 and 1 with more decimals? RAND already gives up to 15 decimal places. To control the number of digits, use =ROUND(RAND(), 4) for four decimals.
Does RANDBETWEEN include the endpoints? Yes, it includes both the bottom and top numbers. For example, =RANDBETWEEN(1, 3) can return 1, 2, or 3.
Why do my random numbers change when I sort the sheet? Because sorting triggers a recalculation. To prevent this, copy the range and paste as values before sorting.
Can I generate random numbers in Excel for the web? Yes, RAND, RANDBETWEEN, and RANDARRAY all work in Excel for the web. The keyboard shortcuts differ slightly – on a Mac, use Cmd+Enter for array formulas.
How do I get a random whole number between 1 and 10 that doesn’t change? Enter =RANDBETWEEN(1,10), then immediately copy the cell and paste as values (right-click > Paste Special > Values). The number stays fixed.
Related
- Random Address in WA? How to Find One Safely
- Unmerge Excel Cells: Quick Steps & Fixes
- How to Be Better at Data Entry: 15 Pro Tips
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Microsoft Word: Remove a Next Page Section BreakTo remove a Next Page section break in Microsoft Word for Microsoft 365 on Windows, select the break…
- Gmail Rules: How to Create and Manage Filters Like OutlookYes. Gmail can automatically sort, label, forward, archive, delete, or otherwise handle messages using filters—the feature that plays…
- How to Convert Data to a Range in ExcelConverting data to a range in Excel turns a table back into a normal range of cells. This…
- How to Create Mail Rules in Outlook and Manage ThemCreate a mail rule in Outlook by choosing a condition, such as a sender or a subject phrase,…
- Tax Audit Form 3CD in Excel: Format and Filing GuideForm 3CD is a prescribed tax-audit statement under India’s Income-tax Rules, but an Excel workbook is generally a…
- Create a Box Plot in Excel: Steps and InterpretationTo create a box plot in Excel for Microsoft 365 on Windows, put each group of numeric observations…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.