Bottom line: Learn how to create a list of unique random numbers with no duplicates or repeats.
Skill level: Easy
My friend and fellow blogger, George Mount, posted a question on Facebook yesterday about creating a list of random non-repeating numbers.
Unfortunately, there is no function built into Excel that will create a list of unique random whole numbers. We can use the RANDBETWEEN function to create random numbers between a certain range, say 1 and 100, but there is nothing in the function to prevent duplicate numbers from being created in the range.
So how else can we solve this problem…?
Sort a List of Unique Numbers in Random Order
One simple way is sort a list of numbers in random order. We can do this by creating a list of numbers, adding a column of random numbers with the RAND function, and sorting the column. Here is a quick screencast that shows how to create the random list.
Here are detailed instructions on how to create the randomly sorted list of numbers.
Step 1: Create a list of numbers
The first step is to create a list of numbers in sequential order. This can be 1 to 10, or 1 to 1,000,000, or anything in between. We can use the Fill Handle to quickly create this list in a column.
We can also use the Fill Series menu to create the list by specifying the stop value (upper limit).
The Fill Series tool is much faster than dragging the fill handle down hundreds or thousands of rows.
Step 2: Create list of random numbers
We now need to create another column of random numbers. We can use either the RAND or RANDBETWEEN functions for this. The RAND function is the fastest because we don't have to specify any arguments. The RAND function returns a random decimal number to the cell.
Input the formula =RAND() in the first cell and double-click the fill handle to copy the formula down.
Step 3: Sort the column of random numbers
The last step is to apply filters to both columns and sort the column that contains the random numbers. Since this column is random, the sort order applied to the first column will be completely random. The first column now contains a list of unique numbers in random order.
The RAND & RANDBETWEEN Functions are Volatile
It's important to note that both the RAND & RANDBETWEEN functions are volatile. This means they recalculate every time Excel calculates, regardless of any formula dependencies.
So, each cell that contains a random function will generate a new random number every time you make a change to the workbook. This includes applying the Sort to the range. To prevent this, we can copy/paste values on the column of random numbers after copying down the formula.
Sort Names or Text in Random Order
This same technique can be used to sort lists of names or text in random order. In the following example we have a list of names in alphabetical order.
We can add random numbers in column B using the RAND function, then sort the range by column B. This will put the names in column A in random order.
I wish my teachers knew about this when I was in school. With the last name of Acampora, I always had to sit in the front row of the classroom and was picked first for class presentations… 🙂
Other Ways to Create a Unique List of Random Numbers
My friend Oz du Soleil from Data Scopic had a great suggestion for creating a list of random numbers when you do NOT need to include every number in the range. For example, let's say we need a list of 100 random numbers between 1 and 1,000.
His suggestion was to use the RANDBETWEEN function to create a long list of random numbers. Fill the formula to more than 100 cells, then copy/paste values. Then use the Remove Duplicates feature to remove any possible duplicates that are generated by RANDBETWEEN.
That will leave us with a long list of unique random numbers. We can then delete an extra cells that we do not need. Maybe Oz can create one of his awesome Excel on Fire YouTube videos to explain this technique in more detail.
What methods do you use to create lists of random numbers? Please leave a comment below with any suggestions or questions. Thank you! 🙂