Using RANDBETWEEN alone cannot prevent duplicates, as the function is designed to select a new random number from a given range every time the worksheet is recalculated. However, you can use RANDBETWEEN in combination with other functions or methods to generate a list of unique random numbers, regardless of your Excel version.
Method 1: The Modern Dynamic Array Method (Excel 365 or 2021)
For users with Excel for Microsoft 365 or Excel 2021, dynamic array formulas provide the most efficient, single-cell solution for generating a unique list of random numbers.
The formula and how it works
A dynamic array formula combines the SORTBY, RANDARRAY, and SEQUENCE functions to return a unique, randomly sorted list.
Formula:=SORTBY(SEQUENCE(max-min+1,,min), RANDARRAY(max-min+1))
SEQUENCE(max-min+1,,min): Generates a sequential array of all possible numbers within your desired range.max-min+1determines the total count of numbers in the sequence.minspecifies the starting number of the sequence.
RANDARRAY(max-min+1): Creates an array of random decimal numbers. The size of this array matches the sequence, providing a random sorting key for each number.SORTBY(...): Sorts the sequential array generated bySEQUENCEusing the random array created byRANDARRAYas the sorting order. This shuffles the numbers into a unique, random list.
Step-by-step example: 10 unique numbers from 1 to 100
- Select a cell where you want the list to begin (e.g., A1).
- Type the formula:
=SORTBY(SEQUENCE(100-1+1,,1), RANDARRAY(100)) - Press Enter.
- The formula will "spill" a list of 100 unique random numbers into the cells below.
Important considerations
- Volatile function:
RANDARRAYis a volatile function, meaning the list will change every time you make a change in the workbook. To fix the numbers, select the list, copy it (Ctrl + C), and then paste as values (Alt + E + S + Vor right-click and choose Paste Special > Values). - Select a smaller list: To get a smaller sample from the sorted array, you can wrap the formula in the
TAKEfunction. For example, to get 10 unique numbers from 1 to 100, use=TAKE(SORTBY(SEQUENCE(100,,1), RANDARRAY(100)),10).
Method 2: The Helper Column Method (All Excel Versions)
If you don't have dynamic array functions, the classic helper column method is a reliable alternative. It works by assigning a random number to each item in a list and then sorting the list based on the random values.
Step-by-step example: Randomize a list of names
Let's say you have a list of names in column A (A2:A11) and need to assign a unique random number to each person.
- Create a helper column. In the cell next to your first item (e.g., B2), enter the formula
=RAND().RANDis a volatile function that produces a random decimal between 0 and 1. - Copy the formula. Drag the fill handle (the small square at the bottom-right corner of the selected cell) down to apply the formula to the rest of the cells in the helper column (e.g., B2:B11).
- Freeze the values. Since
RANDis volatile, the numbers will change constantly. To freeze them, select the helper column (B2:B11), copy it (Ctrl + C), and then paste as values (Alt + E + S + V) in the same location. The formulas are now replaced by their static values. - Sort the data. Select both your original data (A2:A11) and the helper column (B2:B11). Go to the Data tab and click Sort.
- Specify sort criteria. In the Sort dialog box, choose the helper column as the "Sort by" column and select a sort order (e.g., Smallest to Largest). Click OK. Your original list is now in a new, unique random order.
- Delete the helper column. Once the sort is complete, you can delete the helper column.
Method 3: The RANK-based Helper Column Method (All Excel Versions)
This method also uses a helper column but avoids the extra step of sorting, though it still requires a copy-paste as values step.
Step-by-step example
- Generate a list of random numbers. In column B, starting in B2, enter
=RANDBETWEEN(1,1000)(adjust the range as needed). Copy this down for the desired number of cells. - Generate a unique list using RANK.EQ. In column C, starting in C2, enter the formula
=RANK.EQ(B2,$B$2:$B$11,0). This formula ranks each random number in column B. Since there's a very low chance ofRANDBETWEENproducing the exact same number, the ranks will be unique. - Freeze the values. As with the previous method, the formulas are volatile. Select column C, copy, and paste as values in the same location.
- Delete the helper columns. After pasting as values, you can remove columns B and C.
Handling duplicate RANDBETWEEN values
While unlikely, RANDBETWEEN could produce a duplicate. To account for this, a more complex version of the RANK.EQ formula exists, which adds a small increment to differentiate identical numbers.
Modified RANK.EQ formula:=RANK.EQ(B2,$B$2:$B$11,0)+COUNTIF($B$2:B2,B2)-1
This formula:
- Finds the rank of the current value.
- Adds a count for any preceding identical values, ensuring each duplicate gets a distinct rank.
Comparison of methods
| Feature | Dynamic Array Method (Excel 365/2021) | Helper Column Method (All Versions) | RANK-based Method (All Versions) |
|---|---|---|---|
| Effort | Low (Single, self-spilling formula) | Medium (Multiple columns, sort) | Medium (Multiple columns, copy/paste) |
| Efficiency | Highest (Especially for large lists) | Moderate (Requires manual sort) | Moderate (Requires multiple helper columns) |
| Compatibility | Excel 365 & 2021 only | All versions | All versions |
| Reliability | Guaranteed unique numbers | Guaranteed unique numbers | Guaranteed unique numbers (especially with the COUNTIF modification) |
| Best for... | Quickly generating a unique, random list in one step. | Randomizing an existing list or table of data. | Generating a new list of unique random integers without sorting. |