Generate a 6 Digit Random Number: How to Do It

How-to basics · Updated November 22, 2026

To generate a 6-digit random number, use a random number generator (RNG) set to the range 100000–999999, or use a programming function like randint(100000, 999999) in Python. For a truly random result, rely on a hardware-based or cryptographic RNG rather than a simple spreadsheet formula, which is only pseudo-random.

What a 6-Digit Random Number Really Means

A 6-digit number is any integer from 100,000 to 999,999 inclusive. That gives 900,000 possible values. When people ask for a “random” 6-digit number, they usually want one that is uniformly distributed across that range—each number has an equal chance of appearing. Randomness itself is a property of the process, not the number: a single number cannot be “random” in isolation; only the method that produced it can be.

Common uses include password reset codes, two-factor authentication (2FA) tokens, lottery-style draws, verification codes, and unique identifiers in testing. For security-sensitive uses, the random source must be cryptographically secure, meaning it cannot be predicted even if an attacker knows the algorithm and previous outputs.

How Random Number Generators Work

There are two main types of RNGs:

  • True Random Number Generators (TRNGs) – use physical phenomena like electronic noise, radioactive decay, or atmospheric noise. They are genuinely unpredictable but require special hardware or external services.
  • Pseudo-Random Number Generators (PRNGs) – use mathematical algorithms with a seed value. They are deterministic: given the same seed, they produce the same sequence. They are fast and fine for simulations, but not for security unless specifically designed as cryptographically secure PRNGs (CSPRNGs).

Most programming languages and spreadsheet apps use PRNGs. For example, Excel’s RAND() function uses a PRNG with a period of 2^19937 – 1 (the Mersenne Twister). That is statistically random for most purposes but not secure. Python’s random module also uses Mersenne Twister, while the secrets module uses a CSPRNG.

Generating a 6-Digit Number in Excel or Google Sheets

In Excel, to get a random integer between 100,000 and 999,999, use:

  • =RANDBETWEEN(100000,999999) – returns a new random integer each time the worksheet recalculates.
  • =INT(RAND()*900000)+100000 – also works, since RAND() returns a decimal between 0 and 1.

In Google Sheets, the same functions work: =RANDBETWEEN(100000,999999) or =INT(RAND()*900000)+100000. Note that these are volatile—they recalculate on every change or refresh. To keep a fixed number, copy the cell and paste as values (right-click > Paste special > Values only).

For a list of several, drag the formula down. If you need unique numbers, you’ll have to check for duplicates manually or use a more advanced approach, as these formulas can repeat.

Generating in Programming Languages

Here are examples in common languages:

  • Python (secure): import secrets; number = secrets.randbelow(900000) + 100000
  • Python (non-secure): import random; number = random.randint(100000, 999999)
  • JavaScript (browser, secure): crypto.getRandomValues(new Uint32Array(1))[0] % 900000 + 100000 (note: modulo bias, better to use rejection sampling)
  • Java (secure): SecureRandom sr = new SecureRandom(); int n = sr.nextInt(900000) + 100000;
  • C# (secure): RandomNumberGenerator.GetInt32(100000, 1000000) (upper bound exclusive, so 1000000)

For security-critical uses, always choose a CSPRNG. For games or simulations, a standard PRNG is fine.

How to Choose a Truly Random Number

If you need a number that is not just pseudo-random, consider these options:

  1. Use an online service like random.org, which uses atmospheric noise.
  2. Use a hardware RNG device (e.g., a USB dongle that measures electronic noise).
  3. Use your operating system’s built-in cryptographic generator (e.g., /dev/urandom on Linux, CryptGenRandom on Windows).
  4. For a physical method, roll a 10-sided die six times, but that’s not practical for most.

Be aware that “random” in everyday conversation often means “unpredictable enough,” not mathematically perfect. For most non-security uses, a PRNG is sufficient.

Common Problems and Misconceptions

One common mistake is using RAND()*999999 and rounding, which can produce numbers with fewer than 6 digits (e.g., 0.5 becomes 1). Always use the full range from 100000 to 999999.

Another misconception: “random” does not mean “all different.” With 900,000 possible values, duplicates are rare but possible. If you need unique numbers, you must explicitly check for collisions.

Also, some people think that seeding a PRNG with the current time makes it secure. That is false—time seeds are predictable. For security, use a CSPRNG that gathers entropy from multiple sources.

Costs and Alternatives

Generating a 6-digit random number is free in every programming language and spreadsheet. Online services like random.org offer free basic use, but for high-volume commercial use, they have paid APIs. Hardware RNGs cost from a few dollars to hundreds.

Alternatives to random numbers include sequential numbers (like 100001, 100002) or UUIDs. If you need a unique identifier that is hard to guess, a 6-digit number is too small—there are only 900,000 possibilities, so an attacker can brute-force it quickly. For security, use at least 16 random characters or a UUID.

Frequently Asked Questions

Can I generate a 6-digit random number in Excel without repeating? Yes, but you need to use a helper column or VBA. One method: generate a list of all 900,000 numbers, then use INDEX and RAND() to shuffle. For a small list, you can check for duplicates manually or use conditional formatting to highlight them.

Is a 6-digit random number safe for a password reset code? No. 900,000 combinations can be brute-forced in seconds. Use at least 8 random digits (100 million possibilities) or better, a longer alphanumeric token. For 2FA, 6 digits are common but usually rate-limited and expire quickly.

Why does my Excel RANDBETWEEN give the same number every time? That happens if calculation is set to manual. Press F9 to recalculate, or change to automatic calculation. Also, if you copy the cell and paste as values, it becomes static.

What is the difference between RAND and RANDBETWEEN? RAND() returns a decimal between 0 and 1. RANDBETWEEN(bottom, top) returns an integer between the two bounds. To get a 6-digit integer, use RANDBETWEEN(100000,999999).

Can I generate a random 6-digit number on my phone? Yes, many calculator apps have a random function, or you can use a web search for “random number generator” and set the range. For security, use a dedicated authenticator app that generates TOTP codes, which are cryptographically secure.

Are random numbers from a website truly random? It depends. Some sites use pseudo-random algorithms; others use atmospheric noise. Check the site’s documentation. For critical uses, prefer a trusted service or a hardware RNG.

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.