To calculate a random number in Excel, use the RAND function for a decimal between 0 and 1, or the RANDBETWEEN function for a whole number within a range you specify. For example, =RANDBETWEEN(1,100) returns a random integer from 1 to 100. This guide covers the formulas, how to make the numbers static, and common pitfalls.
What You’ll Need
- Microsoft Excel for Microsoft 365 (steps are similar in Excel 2016 and later; Mac differences noted where relevant).
- A worksheet with a cell where you want the random number to appear.
- If you need reproducible results, a seed value (use the
RANDARRAYfunction with a seed, or use a VBA approach—details in the Tips section).
Step-by-Step
- Choose the function that fits your need.
- Decimal between 0 and 1: Use
=RAND(). It returns a value like 0.4523. - Whole number between two bounds: Use
=RANDBETWEEN(bottom, top). For example,=RANDBETWEEN(1,10)returns a random integer from 1 to 10 inclusive. - Decimal between two bounds: Use a formula like
=RAND()*(high-low)+low. For a random decimal between 5 and 10, use=RAND()*5+5.
- Decimal between 0 and 1: Use
- Enter the formula in a cell. Click the cell where you want the result, type the formula (starting with
=), and press Enter. ForRAND(), leave the parentheses empty. ForRANDBETWEEN, replacebottomandtopwith numbers or cell references (e.g.,=RANDBETWEEN(A1,B1)). - Copy the formula to multiple cells (optional). If you need a list of random numbers, select the cell with the formula, drag the fill handle (the small square at the bottom-right corner) down or across. Each cell gets its own random value.
- Make the random numbers static (so they don’t change). By default,
RAND()andRANDBETWEENrecalculate every time the worksheet changes. To freeze the values:- Select the cells containing the formulas.
- Press Ctrl+C to copy (on Mac: Cmd+C).
- Right-click the same selection, choose Paste Special (or use Ctrl+Alt+V on Windows, Cmd+Ctrl+V on Mac).
- In the dialog, select Values and click OK. The formulas are replaced with the current numbers, which no longer change.
- Generate an array of random numbers (Microsoft 365 or Excel 2021 only). Use
=RANDARRAY(rows, columns, min, max, whole). For example,=RANDARRAY(5,1,1,100,TRUE)creates 5 random integers between 1 and 100 in a vertical array. This function spills automatically. - Force a recalculation manually (if needed). Press F9 to recalculate the workbook and get new random values. On Mac, press Fn+F9.
Common Mistakes
- Using
RAND()when you need a whole number.RAND()always returns a decimal. UseRANDBETWEENor round the result. - Forgetting that the numbers change. If you don’t paste as values, every edit to the sheet changes your random numbers, which can break data integrity.
- Using
RANDBETWEENwith reversed bounds. If the bottom is larger than the top, Excel returns a #NUM! error. Always ensure bottom ≤ top. - Assuming
RAND()is truly random. It’s pseudo-random, which is fine for most purposes, but not for cryptography or serious statistical sampling. - Not accounting for duplicates. Random numbers can repeat. If you need unique values, use a different approach (see Tips).
Tips
- To get a random decimal between 0 and 1 with more precision, use
=RAND()and format the cell to show more decimal places (Home > Number > Increase Decimal). - To generate a random date, use
=RANDBETWEEN(DATE(2024,1,1),DATE(2024,12,31))and format the cell as a date. - To create a reproducible random sequence, use the
RANDARRAYfunction with a seed argument (Microsoft 365 only). For example,=RANDARRAY(10,1,1,100,TRUE,42)returns the same 10 integers every time you recalculate, because the seed is 42. This is useful for testing. - To avoid duplicates in a small range, use a helper column with
RAND()and then rank them. For example, put=RAND()in A1:A10, then in B1 use=RANK(A1,$A$1:$A$10)to get a permutation of 1–10. - If you need a random sample from a list, combine
RANDwith sorting. Add a column of random numbers, sort by that column, and take the top N rows.
Troubleshooting
- #NAME? error: This usually means the function name is misspelled. Check that you typed
RANDorRANDBETWEENcorrectly. - #NUM! error: For
RANDBETWEEN, this means the bottom is greater than the top, or the arguments are not numeric. Fix the bounds. - #VALUE! error: This happens if you use text instead of numbers in the arguments. Ensure your cell references point to numeric values.
- The numbers keep changing when I don’t want them to: As mentioned, use Paste Special > Values to freeze them. Alternatively, set calculation to manual (Formulas > Calculation Options > Manual), but then all formulas stop auto-calculating.
- I get the same random number in every cell: This is unlikely with
RAND(), but if you copy a static value, that’s expected. If you useRANDARRAYwith a fixed seed, you’ll get the same sequence—that’s by design.
Frequently Asked Questions
- Can I generate a random number without a formula? Yes, you can use the Data > Data Analysis > Random Number Generation tool (if the Analysis ToolPak is enabled), but it’s not a live formula—it produces static numbers.
- Is there a way to get a random number that never changes? Use the Paste Special > Values method to convert the formula to a static number, or use a VBA macro that writes a value instead of a formula.
- How do I generate a random number between 0 and 100 including decimals? Use
=RAND()*100. This gives a decimal between 0 and 100, inclusive of 0 but exclusive of 100. To include 100, use=RAND()*101and then round down if needed. - Can I use
RANDBETWEENwith negative numbers? Yes, just include the negative numbers in the range, e.g.,=RANDBETWEEN(-10,10). - Why does my random number change when I enter data in another cell? Because
RAND()andRANDBETWEENare volatile functions—they recalculate on any worksheet change. To stop this, set calculation to manual or paste as values. - Is the random number generator in Excel good enough for statistical analysis? For most casual uses, yes. For rigorous simulation or sampling, consider using a dedicated statistical package or a seed-based approach for reproducibility.
Related
- How to Not Rank Zeros in Excel: 4 Fixes
- Data Entry for Healthcare: What It Involves
- Random Number Between 1-50: How to Generate
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Insert a Checkbox in Word: Shortcut and OptionsIn Microsoft Word for Windows, type 2610 and press Alt+X to insert an empty checkbox (☐); use 2611…
- Excel Remove Text and Keep Numbers in a CellTo remove letters and symbols while keeping every digit in an Excel cell, enter =IF(A2="","",TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,""))) in B2, assuming…
- Office Contact List Template Excel: Build a Useful DirectoryAn office contact list template in Excel is a structured worksheet for storing coworkers’ names, roles, work contact…
- Excel: Protect a Sheet but Keep Slicers Usable for UsersYes. In Excel for Microsoft 365 on Windows, unlock the slicer before protecting the worksheet, then protect the…
- Outlook Written Signature: How to Create and Set It UpTo create a written signature in Outlook, type the name and contact details you want at the bottom…
- Split Cells in Google Sheets: Shortcut and StepsGoogle Sheets has no dedicated keyboard shortcut for splitting a cell’s text into columns. The direct method is…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.