Generate Random 4-Digit Numbers with Unique Digits in Excel
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.

- 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.
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.
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.
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.
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.
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.

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. Open WPS Spreadsheet: Launch WPS Office and open a new or existing spreadsheet document.
- 2. Insert the Valid Master List: Paste your 4,472 pre-calculated valid numbers into column A.
- 3. Apply the Function: In an empty cell, enter =INDEX($A$1:$A$4472,RANDBETWEEN(1,4472)) to pull a random valid number.
- 4. Fill to Required Sample Size: Drag the formula down using the fill handle until you reach 420 rows to complete your generation.

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.




