Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Generate Random Whole Numbers in Excel

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To generate a random whole number in Excel, use the RANDBETWEEN function. This function returns an integer between two specified values and updates automatically when the worksheet recalculates. No add-ins or external tools are required—this works in all modern versions of Excel, including Microsoft 365, Excel 2019, 2016, and later.

What You'll Need

  • A blank or existing Excel worksheet
  • Excel 2016 or later (including Microsoft 365)
  • Basic familiarity with typing formulas into cells

Step-by-Step

  1. Open Excel and select the cell where you want the random whole number to appear. For example, click on cell A1.
  2. Type the formula: =RANDBETWEEN(1,100). Replace the numbers 1 and 100 with your desired minimum and maximum values. The first number is the lowest possible result; the second is the highest.
  3. Press Enter. Excel will display a random whole number between your specified range—in this case, between 1 and 100.
  4. To generate a new random number, press F9 on your keyboard. This forces Excel to recalculate all formulas, including RANDBETWEEN, and produces a new value.
  5. If you need multiple random numbers, copy the cell with the formula (Ctrl+C) and paste it into other cells (Ctrl+V). Each paste will generate a unique random number within the same range.
  6. To freeze the random numbers so they don’t change when the sheet recalculates, copy the cells with the formulas, then right-click and choose Paste Values (or use Ctrl+Shift+V and select Values only).
  7. If you need a random number between negative and positive values, such as -50 to 50, use =RANDBETWEEN(-50,50).
  8. To generate a random whole number with no upper limit, you can use a very large number like 9999999, but be mindful of your use case—most applications require a practical range.

Common Mistakes

  • Using decimal numbers in RANDBETWEEN—this function only accepts whole integers. If you type =RANDBETWEEN(1.5,10.7), Excel will round them to 2 and 10, which may not be what you intended.
  • Typing the formula with spaces or incorrect capitalization like =Randbetween(1,100). Excel is case-insensitive for function names, but any extra spaces or typos will cause a #NAME? error.
  • Confusing RANDBETWEEN with RAND(). The RAND() function returns a decimal between 0 and 1, not a whole number. Using RAND() alone will not give you integers unless you wrap it with INT or ROUND, which is more complex and error-prone.
  • Forgetting to freeze values when you need static results. If you copy random numbers and paste them normally, they will keep changing every time you edit another cell or open the file.
  • Using a minimum value higher than the maximum. For example, =RANDBETWEEN(100,1) will return a #NUM! error because the first number must be less than or equal to the second.

Tips

  • Use named ranges for frequently used ranges. For example, name cell B1 as "MinValue" and B2 as "MaxValue", then use =RANDBETWEEN(MinValue,MaxValue). This makes your formulas easier to update and read.
  • If you need a random number from a non-sequential set (like 5, 10, 15, 20), combine RANDBETWEEN with CHOOSE: =CHOOSE(RANDBETWEEN(1,4),5,10,15,20).
  • For lottery-style number generation, use RANDBETWEEN to pick unique numbers, but avoid duplicates by using helper columns or VBA if needed.
  • Use conditional formatting to highlight cells with specific results—for instance, highlight all random numbers over 90 in red to quickly identify outliers.
  • When sharing files, consider turning off automatic calculation (Formulas > Calculation Options > Manual) to prevent unwanted changes. Remember to recalculate manually with F9 when needed.
  • If you're generating many random numbers (e.g., 1000 cells), consider using Excel’s Data Analysis ToolPak for more advanced random number generation with different distributions, though RANDBETWEEN is sufficient for most users.

Troubleshooting

  • #NAME? Error: This means Excel doesn’t recognize the function. Double-check that you typed "RANDBETWEEN" correctly—no typos, no extra spaces, and no missing parentheses. Also, ensure you’re using a supported version of Excel (2007 and later).
  • #NUM! Error: This occurs when the first argument is greater than the second. Fix it by swapping the numbers: if you wrote =RANDBETWEEN(100,1), change it to =RANDBETWEEN(1,100).
  • Numbers keep changing and I want them to stay: Copy the cells, then right-click the destination and select "Paste Values". This replaces the formula with the current number.
  • The formula doesn’t update when I press F9: Check that Calculation Options is set to Automatic (Formulas > Calculation Options > Automatic). If it’s set to Manual, Excel will only recalculate when you press F9.
  • I get the same number every time: This is rare, but can happen on shared or corrupted workbooks. Try saving and reopening the file, or copy the formula to a new worksheet.
  • RANDBETWEEN won’t work in Excel Online: It does work in Excel Online. If you’re seeing an error, check your internet connection or try refreshing the page. If it still fails, use a desktop version.

Frequently Asked Questions

Can I generate random whole numbers without using RANDBETWEEN?

Yes, but it’s less efficient. You can use =INT(RAND()*100)+1 to generate a number between 1 and 100. However, RANDBETWEEN is simpler and designed specifically for this purpose.

Does RANDBETWEEN work on Mac Excel?

Yes. The function works identically on Windows and Mac versions of Excel, including Microsoft 365 and Excel 2019 for Mac.

Can RANDBETWEEN generate negative numbers?

Yes. For example, =RANDBETWEEN(-10,10) will return any whole number from -10 to 10, inclusive.

Why do my random numbers change when I open the file?

Because RANDBETWEEN recalculates every time the worksheet recalculates, which happens when you open, edit, or save the file. To prevent this, paste the results as values.

Is RANDBETWEEN truly random?

It uses Excel’s pseudo-random number generator, which is sufficient for most purposes like simulations, games, or sampling. It is not cryptographically secure, so avoid using it for passwords or encryption keys.

Can I generate unique random numbers without duplicates?

RANDBETWEEN alone cannot guarantee uniqueness. To generate unique numbers, use a helper column with a list of possible values, then use RAND() to sort them and pick the top N. For larger sets, consider using VBA or Power Query.