Dear Analyst
Dear Analyst #39: Generate a random list of names from a list of popular 90s TV characters
Let's say you have a set list of names (in this case TV characters from popular 90s TV shows). You want Google Sheets/Excel to generate a random list of names from your list as if you were picking names out of a hat. How would you do this? It most likely would involve the RAND function, but let's take it a step further and say you want to give the end user the ability to dictate the number of random names to return from your list (e.g. out of my list of 100, give me 5 random names). This is the Google Sheet with all the completed formulas. In addition to the audio format of this episode, I'm also going to start releasing the video tutorial:
https://www.youtube.com/watch?v=icKppdnxJRk
Create your list in column B
Start with your list of names in column B. This can be any list you want to randomize. My list is just a bunch of TV characters from shows I watched when I was a kid.
Source: Fandom
In column A, you put the RAND function and copy it all the way down to the bottom of our list. You'll get a decimal with random numbers. Doesn't look that useful now, but this random number column will drive the rest of the tool to generate your list of random names:
Sort this random list of numbers
It sounds kind of weird, why would you sort a random list of numbers? What does that even mean? As you have probably seen, every time you refresh your Google Sheet or commit an Excel formula by hitting ENTER, all those random numbers in column A will change. This means if you sort this list of random numbers, the sorted list will change too. I put a space in column C so in cell D2, you enter this formula:
The SORT function takes in a range of cells as the first parameter, the sort index as the 2nd (which is just the number column we ant to sort on, column #1), and then true or false for sorting in ascending or descending order. You can also put 0 to indicate false which is what I did in this example to sort in descending order.
The nice thing about the SORT function is that it automatically fills the formula down to the bottom of your data set. This is a relatively new function in Excel since it kind of acts like dynamic array formulas or array-entered formulas. The formula kind of "spills" down for you as your list grows so you don't have to worry about dragging the formula down until the last row in your data set.
A good 'ol VLOOKUP
What does this column of sorted random numbers do for us? Well, we know that each random number in this sorted column corresponds to one of the numbers in column A where we generated the random number. So in column E, we just do a VLOOKUP using column D as our lookup value and columns A:B as our lookup table to get the name associated with the random number in column D:
This is not the usual way you might use VLOOKUP because you're usually using VLOOKUP with some unique identifier as the lookup value. Column A isn't really a unique "TV character ID" since that "ID" changes all the time with the RAND function. We don't really care about that, because now when you refresh the Sheet, column E will always have a random list of names:...