How to Calculate Random Number in Excel

How-to basics · Updated November 23, 2026

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 RANDARRAY function with a seed, or use a VBA approach—details in the Tips section).

Step-by-Step

  1. 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.
  2. Enter the formula in a cell. Click the cell where you want the result, type the formula (starting with =), and press Enter. For RAND(), leave the parentheses empty. For RANDBETWEEN, replace bottom and top with numbers or cell references (e.g., =RANDBETWEEN(A1,B1)).
  3. 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.
  4. Make the random numbers static (so they don’t change). By default, RAND() and RANDBETWEEN recalculate 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.
  5. 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.
  6. 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. Use RANDBETWEEN or 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 RANDBETWEEN with 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 RANDARRAY function 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 RAND with 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 RAND or RANDBETWEEN correctly.
  • #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 use RANDARRAY with 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()*101 and then round down if needed.
  • Can I use RANDBETWEEN with 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() and RANDBETWEEN are 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

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.