Curious Minds

Clear answers to science and history questions

Generate a Random 8-Digit Number in Excel

· 5 min read · Science

To generate a random eight-digit number in Microsoft Excel for Microsoft 365 on Windows, enter =RANDBETWEEN(10000000,99999999) in a cell and press Enter. The result is an integer from 10,000,000 through 99,999,999, inclusive; Excel may recalculate it whenever the worksheet recalculates.

What Counts as an Eight-Digit Number?

An eight-digit number is a whole number whose decimal representation has exactly eight digits. Its smallest possible value is 10,000,000 and its largest is 99,999,999. This definition matters because a number such as 7,654,321 contains only seven digits, while 12,345,678 contains eight.

In the formula above, the first argument sets the lower limit and the second sets the upper limit. RANDBETWEEN can return either boundary, as well as any integer between them. It does not produce a decimal fraction. Because all possible results are positive, the formula cannot return a leading zero; that is appropriate when the request is for an eight-digit number rather than an eight-character code.

Generate One Number in Excel

Enter the formula directly in a worksheet cell. For example, type =RANDBETWEEN(10000000,99999999) into A1 and press Enter. Excel displays one randomly selected integer. The particular value is not predictable from the formula alone, and it can differ when the workbook recalculates.

For a column of results, enter the formula in the first cell and copy it down. With the formula in A1, drag the fill handle at the cell’s lower-right corner down to the other rows, or copy and paste it into a selected range. Each cell has its own formula and will generally show a different result, though random selection does not guarantee uniqueness.

Excel for the web also supports RANDBETWEEN. On Excel for Mac, the same formula works; the function syntax does not change. Keyboard shortcuts can vary by keyboard and platform, but recalculation is commonly triggered with F9 in Windows desktop Excel. On Mac, use the recalculation shortcut shown for your Excel version and keyboard settings, or use Formulas > Calculate Now.

Generate Several Numbers and Check for Duplicates

To produce many values, fill the formula down as described above. If you need every value to be unique, repeated random formulas alone are not enough: duplicates are possible, especially when the requested list is large compared with the number of available values. For a small sample, you can generate extra values and check them for duplicates, then replace any repeats. For a larger or strict requirement, use a method that selects from a defined set without replacement rather than assuming random draws will be unique.

In Microsoft 365 or Excel 2021, a dynamic-array formula can generate a list of random integers. With enough clear cells below the formula cell for the results to spill, enter =RANDARRAY(10,1,10000000,99999999,TRUE) to request ten rows and one column of integers in the range. This does not ensure ten distinct results. If the spill area contains data, Excel reports a spill error; clear the obstructing cells and enter the formula again.

To find repeated values in a list, select the cells and use Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values. This highlights duplicates but does not remove them. Review the values before deleting anything, particularly if they are being used as identifiers.

Keep a Generated Value from Changing

RANDBETWEEN is a volatile function: its output can change when Excel recalculates, such as after editing cells or opening the workbook. That is useful when you want a fresh random draw, but inconvenient when you need to retain a chosen result.

To freeze a result, first generate it, then copy the cell and paste only its value back in place. In Windows Excel, copy the cell, right-click the destination, and choose Paste Special > Values (the menu may present a Values icon). Alternatively, copy the cell, then use Home > Paste > Paste Values. After replacing the formula with its value, recalculation will no longer change that cell. Keep a copy of the original formula elsewhere if you may need to generate another draw.

Number Versus Eight-Character Code

A number and a code that happens to contain digits are not always the same thing. If you need exactly eight characters and the first character may be zero—for example, a test code like 00482173—then an ordinary number is the wrong representation. Excel removes leading zeros from numeric values because they do not affect the number’s value.

For a fixed-width display, you can format a number to show eight digits, but this only changes how it appears; it does not turn the underlying value into text. A custom number format such as 00000000 displays leading zeros for shorter numbers. If the value must be preserved as an identifier, exported with its zeros, or compared as text, store it as text instead. Choose the approach based on what the data represents, not only on how it looks in the cell.

Randomness, Security, and Practical Limits

Excel’s random functions are suitable for ordinary worksheet tasks such as sample data, classroom exercises, and casual simulations. They are not a dependable way to create security credentials, password-reset tokens, encryption keys, or other secrets. A spreadsheet’s random output should not be treated as cryptographically secure. For sensitive uses, rely on a purpose-built secure random generator or the approved system used by your organization.

Also remember that an eight-digit value is not automatically unique. There are 90,000,000 possible eight-digit positive integers, from 10,000,000 to 99,999,999. A random draw may repeat an earlier result, and the chance of a repeat rises as more values are drawn. If uniqueness is essential, maintain a duplicate check or use a controlled allocation method that rules out previously assigned values.

Frequently Asked Questions

What formula generates a random eight-digit number in Excel?
Use =RANDBETWEEN(10000000,99999999). It returns an integer between the two limits, including both limits.

Can the result start with zero?
Not as an eight-digit number: values with a leading zero have fewer than eight digits numerically. If you need an eight-character code that can begin with zero, use text or a suitable display format.

Why did my random number change?
RANDBETWEEN recalculates when Excel recalculates the worksheet. Copy the cell and paste its value to keep the current result fixed.

Can Excel generate a list without duplicates?
Repeated calls to RANDBETWEEN can produce duplicates, including when using RANDARRAY. Generate values and check them, or use a selection process that explicitly excludes numbers already chosen.

Is an Excel-generated number safe as a password or token?
No. Excel’s worksheet random functions are not intended to provide cryptographic security. Use a security-focused generator for secrets and follow the relevant system or organizational requirements.

In this article
  1. What Counts as an Eight-Digit Number?
  2. Generate One Number in Excel
  3. Generate Several Numbers and Check for Duplicates
  4. Keep a Generated Value from Changing
  5. Number Versus Eight-Character Code
  6. Randomness, Security, and Practical Limits
  7. Frequently Asked Questions