Random Number Function in Excel: How to Generate Random Numbers
In this article
Excel’s random number functions generate unpredictable numeric values for simulations, sampling, or masking data. You can create integers or decimals between 0 and 1, or specify custom ranges. No add-ins or special permissions are required—just Excel installed on Windows, Mac, or online.
What You'll Need
- Microsoft Excel (2010 or later for modern functions)
- A worksheet open and ready for input
- No additional tools or internet access needed
Step-by-Step
- Open your Excel workbook and click the cell where you want the random number to appear.
- For a decimal between 0 and 1 (e.g., 0.372), type
=RAND()and press Enter. This function recalculates every time the sheet changes. - For a random integer between two numbers (e.g., 10 and 50), type
=RANDBETWEEN(10,50)and press Enter. Replace 10 and 50 with your desired lower and upper bounds. - To generate a column of random decimals, enter
=RAND()in the first cell, then drag the fill handle down (or double-click it) to copy into adjacent rows. - For a column of random integers, use
=RANDBETWEEN(1,100)in the first cell and copy down similarly. - To lock a random value (prevent recalculation), copy the cell(s) with the formula, right-click the same or another location, choose Paste Special > Values, and click OK. This pastes static numbers instead of formulas.
- To generate unique random numbers (no duplicates) in a range, first list your full data set (e.g., 1 to 100 in column A), then in column B enter
=RAND(), copy column B, paste as values, then sort column A by column B’s values and take the top N rows.
Common Mistakes
- Using
=RANDBETWEENwith text—this function only works with whole numbers; for decimals, use=INT((upper-lower+1)*RAND())+loweror scaleRAND()manually. - Expecting static numbers after copying
RAND()orRANDBETWEEN()formulas—by default, Excel recalculates them on every edit, so values change unless you paste as values. - Entering commas instead of semicolons in non-English locales (e.g., Excel in German uses
=ZUFALLSZAHL()or=ZUFALLSBEREICH(1;100)); check your regional settings under File > Options > Language. - Confusing
RAND()andRANDBETWEEN()syntax:RAND()takes no arguments, whileRANDBETWEENrequires two numbers (lower, upper) separated by a comma or semicolon depending on locale.
Tips
- Press F9 to force a full recalculation of all formulas—including random ones—anytime you want new values without changing the sheet.
- Use
=RAND()*100+50to generate decimals between 50 and 150 (multiply by the range width, then add the lower bound). - To avoid duplicates in sampling, combine
RAND()withRANK.EQor use=UNIQUE(RANDARRAY(100))in Excel 365/2021 to create a list of unique random decimals, then sort and trim. - For reproducible random sequences (e.g., for testing), set a seed by linking to a fixed cell:
=RAND()*N$1where N1 holds a constant multiplier (though true seeding requires VBA).
Troubleshooting
- Formula shows as text (e.g., "=RAND()" instead of a number): Check the cell format—right-click the cell, choose Format Cells, and ensure Number is selected. Also verify the cell isn’t preceded by an apostrophe (') in the formula bar.
- RANDBETWEEN returns #NAME? This means Excel doesn’t recognize the function. Confirm you’re using Excel 2010 or newer, and that Analysis ToolPak isn’t required (it isn’t for
RANDBETWEENin modern versions). Try typing=RANDBETWEEN(1,10)again, ensuring correct spelling and parentheses. - Values keep changing unexpectedly: This is normal behavior for volatile functions like
RAND()andRANDBETWEEN(). To fix, copy the cells and use Paste Special > Values. Alternatively, go to Formulas > Calculation Options and set to Manual to stop automatic recalculation (but remember to press F9 to update when needed). - No random numbers appear when dragging the fill handle: Ensure the fill handle is enabled—go to File > Options > Advanced, scroll to Editing options, and check Enable fill handle and drag-and-drop.
Frequently Asked Questions
Can I generate a random number that doesn’t change?
Yes—after entering=RAND() or =RANDBETWEEN(), copy the cell, right-click, choose Paste Special, select Values, and click OK. This replaces the formula with a static number.How do I generate random numbers between 0.5 and 2.0?
Use=RAND()*(2-0.5)+0.5, which scales and shifts the 0–1 range to 0.5–2.0. For integers only, use =INT((2-0.5+1)*RAND())+0 or adjust bounds to whole numbers first.Why does my RANDBETWEEN give the same number every time?
If values never change, your calculation mode may be set to Manual (Formulas > Calculation Options). Switch to Automatic, or press F9 to force recalculation. Also, verify you didn’t paste as values by accident.Is there a way to prevent duplicates in a list of random numbers?
In Excel 365/2021, use=UNIQUE(RANDARRAY(20,1,1,100,TRUE)) to get 20 unique integers between 1 and 100. In older versions, add a helper column with =RAND(), sort by it, then take the first N rows to ensure uniqueness.Can I use random numbers in a pivot table?
Yes—but sinceRAND() recalculates on refresh, the values will change each time the pivot updates. To keep them stable, generate the random numbers in a normal range first, paste as values, then use that static range as the pivot source.Does RAND() work on Excel for Mac or online?
Yes—bothRAND() and RANDBETWEEN() work identically across Excel for Windows, Mac, and Excel Online (via browser). Regional syntax may differ slightly (e.g., semicolons instead of commas), so adjust accordingly under your app’s language settings.