Function Problems

Generate Random 4-Digit Numbers with Unique Digits in Excel

Nimra MalikNimra Malik Nov 2, 2026 870 views

Question details

The user needs to generate 420 random four-digit numbers between 1234 and 9876, ensuring that no individual number has repeating digits. Duplicate numbers among the final 420 results are acceptable.

How to Generate Random 4-Digit Numbers with Unique Digits
Product
Spreadsheet
Device & OS
not provided
Scenario
Creating a specific sample of random 4-digit numbers bounded by a customized range while strictly prohibiting duplicate digits inside any single generated number.
Observed behavior
The user requires exactly 420 results drawn from a restricted pool of valid numbers within the 1234-9876 range. The total pool size is 4,472 numbers, which is lower than the raw probability calculation (4,536) due to range constraints.
Before you start

Prepare a helper column in your spreadsheet containing all the valid four-digit combinations that meet your unique-digit criteria before applying the random selection formula.

Solution 1Recommended

Use INDEX and RANDBETWEEN with a Pre-filtered Helper List

Since formulaic generation of unique internal digits within specific boundaries is highly complex, the most reliable method is selecting randomly from a generated list of the 4,472 valid permutations.

A calculation of 9 × 9 × 8 × 7 yields 4,536 possible unique-digit permutations. However, because the requested range specifically starts at 1234 and ends at 9876, combinations like 1023 or 9877-9999 are excluded, leaving exactly 4,472 valid numbers.

By listing these 4,472 valid numbers in a single column, you can use Excel's random lookup functions to pull 420 results from that specific pool.

1
Prepare the Helper List

Generate or paste the list of the 4,472 valid 4-digit numbers (between 1234 and 9876 with no repeating digits) into column A, specifically from cell A1 down to A4472.

2
Enter the Random Lookup Formula

Click on a blank cell where you want your 420 numbers to start (e.g., cell C1). Type the formula: =INDEX($A$1:$A$4472,RANDBETWEEN(1,4472)) and press Enter.

3
Generate the 420 Results

Click on cell C1 again, grab the fill handle (the small square at the bottom-right of the cell), and drag it down to row 420 to generate your required sample size.

Use INDEX and RANDBETWEEN with a Pre-filtered Helper List
Freeze the Random Numbers: RANDBETWEEN is a volatile function and will recalculate every time you make a change in the sheet. Select your generated 420 numbers, copy them, and use 'Paste Special > Values' to make them permanent.

Generate Complex Random Datasets with WPS Spreadsheet

WPS Spreadsheet fully supports advanced array formulas, INDEX, and RANDBETWEEN functions, making it incredibly easy to pull specific randomized samples from highly constrained data pools.

  1. 1. Open WPS Spreadsheet: Launch WPS Office and open a new or existing spreadsheet document.
  2. 2. Insert the Valid Master List: Paste your 4,472 pre-calculated valid numbers into column A.
  3. 3. Apply the Function: In an empty cell, enter =INDEX($A$1:$A$4472,RANDBETWEEN(1,4472)) to pull a random valid number.
  4. 4. Fill to Required Sample Size: Drag the formula down using the fill handle until you reach 420 rows to complete your generation.
100% compatibility with Microsoft Excel formulas and functionsFast processing for large helper columns and random data generationIntuitive Paste Special features to easily freeze volatile functions
microsoft office alternative - wps office

Frequently Asked Questions

Why is the total number of combinations 4,472 instead of 4,536?

The math formula (9 × 9 × 8 × 7) calculates 4,536 total permutations for a 4-digit number with unique digits. However, this includes valid unique-digit numbers that fall outside your 1234 to 9876 range (such as 1023, 1024, etc.). When you restrict the bounds strictly between 1234 and 9876, the total valid count drops exactly to 4,472.

How can I prevent duplicate results among the 420 generated numbers?

If you do not want duplicates in your final 420 list, do not use RANDBETWEEN. Instead, in column B (next to your 4,472 helper list), enter the formula =RAND() for all rows. Then, sort column B from smallest to largest. The first 420 rows in column A will now be a random, non-repeating sample.

How do I stop my random numbers from refreshing every time I type?

Functions like RANDBETWEEN update constantly. To stop this, highlight all 420 generated numbers, press Ctrl+C to copy, then right-click the same selection and click 'Paste as Values'. This removes the underlying formula and locks the numbers in place.