Random 5 Digit Number: How to Generate One

How-to basics · Updated November 23, 2026

The simplest way to generate a random 5-digit number is to use a dedicated random number generator tool, a spreadsheet formula like =RANDBETWEEN(10000,99999) in Excel, or a programming language’s random function. A 5-digit number ranges from 10000 to 99999, and any method that picks uniformly from that range works.

What Counts as a 5-Digit Number

A 5-digit number is any integer from 10,000 to 99,999. That means the smallest is 10,000 (not 0, which is 1 digit) and the largest is 99,999. Numbers like 00001 are not considered 5-digit in standard math because leading zeros are not counted as digits. However, some contexts—like PIN codes or lottery-style draws—allow leading zeros, so a string like “00456” might be called a 5-digit code. If you need a true 5-digit number, always start at 10,000.

How to Generate a Random 5-Digit Number in Excel

In Microsoft Excel (Microsoft 365 on Windows), the easiest way is the RANDBETWEEN function. It returns a random integer between two specified values, inclusive.

Assuming you want the result in cell A1, enter:

=RANDBETWEEN(10000,99999)

This gives you a random number from 10,000 to 99,999. Press F9 to recalculate and get a new number. On Mac, the shortcut is Fn+F9 (or just Cmd+= to recalculate the worksheet).

If you need a list of 10 random 5-digit numbers, put the formula in A1 and drag it down to A10. Each cell will show a different random value.

For older Excel versions (2016 and earlier), RANDBETWEEN works the same. If you want to avoid the function recalculating every time the sheet changes, copy the result and paste as values (right-click > Paste Special > Values).

Generating with a Programming Language

In Python, you can use the random module:

import random
print(random.randint(10000, 99999))

In JavaScript (in the browser console):

Math.floor(Math.random() * 90000) + 10000

This works because Math.random() returns a decimal between 0 (inclusive) and 1 (exclusive). Multiplying by 90000 gives a range from 0 to 89999.999…, then Math.floor rounds down to an integer from 0 to 89999, and adding 10000 shifts it to 10000–99999.

In R, use sample(10000:99999, 1). In Java, ThreadLocalRandom.current().nextInt(10000, 100000) (the upper bound is exclusive).

Using Online Random Number Generators

Many websites offer free random number generators. Typically, you set the minimum to 10000 and maximum to 99999, then click “Generate.” Some allow you to generate multiple numbers at once and even sort or remove duplicates. These tools use cryptographic or pseudo-random algorithms, but for most casual purposes they are fine. Be cautious about entering sensitive data—use a generator that runs entirely in your browser if you need privacy.

Common Misconceptions: Are They Truly Random?

Most computer-generated random numbers are not truly random—they are pseudo-random, meaning they follow a deterministic algorithm that appears random. For everyday tasks like picking a lottery number or a prize winner, pseudo-random is sufficient. For security (e.g., generating a password or a cryptographic key), you need a cryptographically secure random number generator, which uses entropy from your system. In Excel, RANDBETWEEN is not cryptographically secure; do not use it for security purposes.

How to Choose a Method

Consider your context:

  • Casual use (e.g., picking a random number for a game): any method works.
  • Spreadsheet work: use RANDBETWEEN in Excel or Google Sheets.
  • Programming: use the language’s built-in random function.
  • Security-sensitive: use a cryptographically secure generator (e.g., Python’s secrets module, or JavaScript’s crypto.getRandomValues).

If you need to avoid repeats (like drawing multiple numbers without replacement), you’ll need a method that tracks used numbers. In Excel, you could generate a list and then remove duplicates manually, or use a more advanced approach with RAND and sorting.

Frequently Asked Questions

Can I generate a 5-digit number with leading zeros? Yes, but it’s not a true 5-digit number. If you need a code like “00123”, treat it as text. In Excel, you can format a number with leading zeros using custom format 00000 (right-click > Format Cells > Custom > type 00000). Or use =TEXT(RANDBETWEEN(0,99999),"00000") to get a 5-character string.

How do I generate a random 5-digit number in Google Sheets? Use the same =RANDBETWEEN(10000,99999) formula. It works identically to Excel. To make it static, copy and paste as values (right-click > Paste special > Values only).

Is there a way to generate a random 5-digit number without a computer? Yes, you can use physical methods like rolling dice, drawing numbered balls, or using a random number table from a book. For example, roll a 10-sided die five times to get digits, but the first digit must be 1-9 to ensure a 5-digit number (or allow leading zero if you treat it as a code).

Why does my Excel RANDBETWEEN number change every time I type something? Because RANDBETWEEN is a volatile function—it recalculates whenever the worksheet changes. To freeze the value, copy the cell and paste as values (right-click > Paste Special > Values).

Can I generate a random 5-digit number that is not repeated in a list? Yes, but you need to check for duplicates. In Excel, you can generate a large list and then use Remove Duplicates (Data > Remove Duplicates). For a truly non-repeating sequence, you’d need a more complex approach like shuffling a list of all possible numbers, which is impractical for 90,000 items but doable in programming.

What is the probability of getting a specific 5-digit number? If the generator is uniform, the probability is 1 in 90,000 (since there are 90,000 possible numbers from 10000 to 99999). That’s about 0.0011%.

Safety and Accuracy Notes

If you use a random number for a password or security token, never rely on RANDBETWEEN or typical Math.random()—these are not secure. Instead, use a dedicated secure random generator. Also, if you are using a random number for a contest or drawing, ensure the method is unbiased and documented. For spreadsheet formulas, always double-check the range (10000 to 99999) to avoid accidentally including 9999 or 100000.

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.