Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Random Non-Repeating Numbers: How-To

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To generate random numbers that don't repeat in Excel, use the RAND() or RANDBETWEEN() functions combined with a helper column and sorting, or use RANDARRAY() with UNIQUE() in Microsoft 365. The simplest reliable method is to create a list of sequential numbers, assign each a random value with RAND(), then sort by that random column and take the top N. This guarantees no duplicates because the original numbers are unique.

What You'll Need

  • Microsoft Excel (any modern version; some functions like RANDARRAY and UNIQUE require Microsoft 365 or Excel 2021+).
  • A blank worksheet or an existing sheet where you can add helper columns.
  • Basic familiarity with entering formulas and sorting data.

Step-by-Step

  1. Decide the range and count. For example, you want 10 unique random numbers between 1 and 100. Enter the lower bound in cell A1 (e.g., 1) and the upper bound in A2 (e.g., 100). Enter the count you need in A3 (e.g., 10).
  2. Create a list of all possible numbers. In a new column (say column C), starting at C2, enter the formula =SEQUENCE(A2-A1+1,1,A1) if you have Microsoft 365. This spills a list from 1 to 100. If you don't have SEQUENCE, type the first number in C2, the second in C3, select both, and drag the fill handle down to C101 to create the full list.
  3. Add a random value for each number. In cell D2, enter =RAND(). Copy this formula down to D101 (one row per number in your list). Each row now has a unique number from your range and a random decimal between 0 and 1.
  4. Sort by the random column. Select the entire range C2:D101 (or your equivalent). Go to the Data tab and click Sort. Choose to sort by column D (the RAND column) in ascending or descending order—either works. Click OK. The numbers in column C are now in random order.
  5. Take the first N numbers. The top 10 cells in column C (C2:C11) are your 10 unique random numbers. Copy them to your desired location. Because the original list had no duplicates and you simply reordered it, the selected numbers are guaranteed unique.
  6. Convert to static values (optional). The RAND() formulas recalculate every time the sheet changes, which would reshuffle your numbers. To freeze them, copy the selected numbers and use Paste Special > Values into a new location. Then you can delete the helper columns.

Common Mistakes

  • Using RANDBETWEEN repeatedly without checking for duplicates. RANDBETWEEN can produce the same number multiple times. If you need uniqueness, you must use a method that ensures it, such as the sort-and-take approach above.
  • Forgetting that RAND() recalculates. Every time Excel recalculates (e.g., you enter data elsewhere), RAND() changes. If you don't convert to values, your "random" numbers will keep changing, which may not be what you want.
  • Sorting only part of the data. If you sort only column C without column D, the random values won't stay paired with their numbers, breaking the randomness. Always select both columns before sorting.
  • Using the wrong range size. If you need 10 unique numbers from 1 to 10, your list must have exactly 10 numbers. If you accidentally include more or fewer, you might get duplicates or not enough numbers.
  • Assuming RANDARRAY alone gives unique values. RANDARRAY can generate an array of random numbers, but they are not guaranteed unique. To get unique values, combine it with UNIQUE or use the sort method.

Tips

  • Use a dynamic array formula for a quick unique list (Microsoft 365). Enter =INDEX(UNIQUE(RANDARRAY(1000,1,1,100,TRUE)),SEQUENCE(10)) to get 10 unique random integers between 1 and 100. This works by generating many random integers, removing duplicates with UNIQUE, and taking the first 10. Increase the 1000 if you get a #REF! error (meaning fewer than 10 unique values were generated).
  • Generate unique random numbers without sorting. Use =LARGE(ROW(INDIRECT("1:100"))*NOT(COUNTIF($E$1:E1,ROW(INDIRECT("1:100")))),RANDBETWEEN(1,100-ROW()+1)) entered as an array formula (Ctrl+Shift+Enter in older Excel). This is more complex and not recommended for beginners.
  • Use a helper column with RAND() and then remove duplicates. If you just need a set of random numbers and don't care about the exact range, you can use RANDBETWEEN to fill a column, then use Data > Remove Duplicates to eliminate repeats. However, this may leave you with fewer numbers than you need, so generate extra.
  • Freeze your random numbers by copying and pasting as values immediately after generating them, so they don't change when the sheet recalculates.
  • For reproducible randomness, you can use =RAND() with a seed, but Excel doesn't have a built-in seed function. Instead, you can use a fixed random value from a website or generate once and paste as values.

Troubleshooting

  • My numbers keep changing. This is because RAND() and RANDBETWEEN() are volatile functions. Convert your results to static values by copying and using Paste Special > Values.
  • I get duplicates. If you used RANDBETWEEN alone, duplicates are possible. Switch to the sort method or use the UNIQUE function with RANDARRAY. Also check that your source list has no duplicates.
  • The formula returns #REF! or #VALUE!. For the dynamic array method, increase the number of random values generated (e.g., from 1000 to 5000) to ensure enough unique numbers. For array formulas, make sure you entered them correctly with Ctrl+Shift+Enter (if using older Excel).
  • Sorting doesn't randomize. Ensure you are sorting by the RAND column, not by the number column. Also, make sure you select both columns before sorting.
  • I need numbers from a non-sequential range (e.g., 5,10,15...). Create your list of allowed numbers manually or with a formula, then apply the same sort-by-random method.

Frequently Asked Questions

Can I generate random numbers without duplicates using a single formula?

Yes, in Microsoft 365 you can use =INDEX(UNIQUE(RANDARRAY(1000,1,1,100,TRUE)),SEQUENCE(10)) to get 10 unique random integers between 1 and 100. Adjust the parameters as needed.

Why does RANDBETWEEN sometimes give me the same number twice?

RANDBETWEEN picks each number independently, so repeats are possible. To avoid duplicates, use a method that ensures uniqueness, such as sorting a list of unique numbers by a random column.

How do I stop Excel from recalculating my random numbers?

After generating your numbers, copy them and paste as values (Paste Special > Values). This replaces the formulas with static numbers that won't change.

Can I use this method for a range like 1 to 1000?

Yes, the sort method works for any size range. Just create a list of all numbers in the range and follow the steps. For very large ranges, the dynamic array formula may be more efficient.

What if I need random numbers that are not integers?

Use =RAND() to generate random decimals between 0 and 1, then scale and shift as needed (e.g., =RAND()*(100-1)+1 for numbers between 1 and 100). To ensure uniqueness, use the sort method with these random decimals.

Does this work in Excel for Mac?

Yes, the functions and sorting method work in Excel for Mac. The interface may look slightly different, but the steps are the same.