Google Sheets Cheat Sheet

Generate A Random Item From A List In Google Sheets

These formulas will work when you need to get:

A single random item from a list in a column:

=INDEX(FILTER(A2:A,A2:A<>""), RANDBETWEEN(1, COUNTA(A2:A)))

5 random items from a list in a column:

=ARRAY_CONSTRAIN( SORT( FILTER(A2:A, A2:A<>""), RANDARRAY( COUNTA(A2:A), 1), TRUE), 5, 1)

5 random, unique items from a list that contains duplicates (in a column):

=ARRAY_CONSTRAIN( UNIQUE( SORT( FILTER(A2:A, A2:A<>""), RANDARRAY( COUNTA(A2:A), 1), TRUE)), 5, 1)

In all three, A2:A references the list from which you want an item or items.

Other formulas including getting random items from rows and tables instead of columns AND explanations about how to create these formulas are below.

Google Sheets can randomly select an item from a list with a formula.

Question is, what do you need to do?

ABCD
1I need:From:
2One itemColumnRowTable
3Multiple itemsColumnRowTable
4No repeatsColumnRowTable

How To Randomly Select From A List In Google Sheets

To generate a random item from a list you'll need a formula that combines the INDEX, RANDBETWEEN, and COUNTA functions.

The INDEX function takes in data and outputs a row, column, or single data point from a row and/or column:

=INDEX(reference, [row], [column])
  • reference = range from which to extract data (row/s and/or column/s)
  • [row] = [optional] which row to extract data from (1 = top-most row)
  • [column] = [optional] which column to extract data from (1 = left-most column)

To select an item randomly from a list, the reference in your INDEX function will be the list itself.

The [row] and [column] numbers will depend on if you're taking from a column, row, or table:

  • List in column = you only need [row] (as there's only one column in reference)
  • List in row = you only need [column] (as there's only one row in reference)
  • List in table = you need both [row] and [column]

Let's assume you have your list in a column.

The [row] number will need to be a random number between 1 and the number of items in your list.

There's a function for that:

=RANDBETWEEN(low, high)
  • low = lowest bound of random range (inclusive)
  • high = highest bound of random range (inclusive)

Now you're getting somewhere:

=INDEX(reference, RANDBETWEEN(low, high))

The RANDBETWEEN function is what's known as a volatile function.

This means it recalculates every time the sheet changes or recalculates regardless of whether the change or recalculation is associated with the formula that contains the volatile function.

This makes it easy to create a button to generate a random item from your list.

Simply insert a checkbox in a nearby cell (go to InsertCheckbox) and everytime you click the checkbox a new item is chosen at random.

If you want to stop this from happening, copy the cell with the formula (Ctrl+C or ⌘+C) and paste it as a value (Ctrl+Shift+V or ⌘+Shift+V).

This removes the formula and leaves you with your random item that won't change.

As mentioned above, to generate a random item from a list your RANDBETWEEN low is always going to be 1 so that it can potentially pick the first item in your list.

That means all that's left to calculate is the high.

You don't want to extract a [row] from your reference list that doesn't exist. That means the high bound should not be higher than the number of items in your list.

There's a formula for that too:

=COUNTA(value1, [value2, ...])

The COUNTA function returns the number of values present, whether they're numbers, text, or boolean.

If you add the INDEX reference as an argument of the COUNTA function, it will return how many items are in the list, which is the number you need for the RANDBETWEEN high.

Here's the final formula:

=INDEX(A2:A, RANDBETWEEN(1, COUNTA(A2:A)))

And an example that generates a random name from a list (click the checkbox to refresh the volatile RANDBETWEEN function):

ABC
1ListFormulaOutput
2Michael Scott=INDEX(A2:A,RANDBETWEEN(1,COUNTA(A2:A)))Oscar Martinez
3Dwight Schrute
4Jim Halpert
5Pam Beesly
6Andy Bernard
7Stanley Hudson
8Phyllis Vance
9Angela Martin
10Oscar Martinez

There you have it, a working randomizer in Google Sheets!

This is the perfect setup to pick the winner of a contest at random when you have all of the contestants in a Google Sheet.

There is an assumption being made that your list does not contain blanks.

If it does contain blanks the items at the end of your list will not be able to be randomly selected as blanks aren't counted by COUNTA.

As a result, the RANDBETWEEN high won't be enough to pull from the end of the reference list and your random result will sometimes be one of the blank cells.

To avoid this, you can filter out the blanks from the reference list using the FILTER function:

=INDEX(FILTER(reference,reference<>""), RANDBETWEEN(1, COUNTA(reference)))

In the example above this formula would be:

=INDEX(FILTER(A2:A,A2:A<>""), RANDBETWEEN(1, COUNTA(A2:A)))

If your list is in a row instead of a column, use this formula:

=INDEX(A2:2,,RANDBETWEEN(1,COUNTA(A2:2)))

And if you have blanks in the row:

=INDEX(FILTER(A2:2,A2:2<>""),,RANDBETWEEN(1,COUNTA(A2:2)))

Here you're omitting the [row] from the INDEX function and including only the [column].

If your list is in a table of data (in both rows and columns), use this formula:

=INDEX(A2:C5,RANDBETWEEN(1,ROWS(A2:C5)),RANDBETWEEN(1,COLUMNS(A2:C5)))

It includes both a [row] and [column] in the INDEX function and takes advantage of the ROWS and COLUMNS functions to return how many rows and columns are in the selected range.

hand pointing emoji hand pointing emoji

FREE RESOURCE

Google Sheets Cheat Sheet

12 exclusive tips to make user-friendly sheets from today:

Google Sheets Cheat Sheet

You'll get updates from me with an easy-to-find "unsubscribe" link.

Randomly Select Multiple Items From A List In Google Sheets

To get a random sample from a list in Google Sheets, things get a little more complicated than if you were to just get a single item.

The INDEX function used to solve the single item problem won't work efficiently to solve this problem.

INDEX is designed to return a single value or an entire array of values (whole column or whole row).

What you want is some of the values, not one or all.

So which formula can get you a subset?

ARRAY_CONSTRAIN is a good option.

=ARRAY_CONSTRAIN(input_range, num_rows, num_cols)
  • input_range = the array of values to get a sample from
  • num_rows = how many rows to sample
  • num_cols = how many columns to sample

This is perfect! Now all you need to do is randomly sort your list of items and ARRAY_CONSTRAIN will return a sample of however many you need.

And as usual Google Sheets has your back with functions to allow you to do just that:

=SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2, ...])
  • range = the array of values to be sorted
  • sort_column = which column in the range OR an external column to sort by
  • is_ascending = TRUE or FALSE option for ascending or descending sort
  • [sort_column2, is_ascending2, ...] = [optional] additional sort columns

For your needs the range would be the list of items to pull from (with a FILTER function attached to remove blanks).

The sort_column would be an array of random numbers with the same number of rows and columns as the filtered range.

is_ascending can be TRUE or FALSE, it doesn't matter as the range will be sorted randomly.

This is where you're up to:

=ARRAY_CONSTRAIN( SORT( FILTER(range, range<>""), sort_column, is_ascending), num_rows, num_cols)

To continue you need an array of random numbers for your sort_column.

Once again, Google sheets delivers:

=RANDARRAY(rows, columns)
  • rows = the number of rows of random numbers to generate
  • columns = the number of columns of random numbers to generate

To get the number of rows and/or columns as the filtered range. You can use the COUNTA function to return the number of non-blank values in the range.

Let's put it all together:

=ARRAY_CONSTRAIN( SORT( FILTER(range, range<>""), RANDARRAY( rows, columns), is_ascending), num_rows, num_cols)

That's it!

Here's a working formula to get 5 items from a list in a column:

=ARRAY_CONSTRAIN( SORT( FILTER(A2:A, A2:A<>""), RANDARRAY( COUNTA(A2:A), 1), TRUE), 5, 1)

Here's an example (click the checkbox to refresh the volatile RANDARRAY function):

ABC
1ListFormulaOutput
2Michael Scott=ARRAY_CONSTRAIN( SORT( FILTER(A2:A, A2:A<>""), RANDARRAY( COUNTA(A2:A), 1), TRUE), 5, 1)Pam Beesly
3Dwight SchruteDwight Schrute
4Jim HalpertStanley Hudson
5Pam BeeslyPhyllis Vance
6Andy BernardMichael Scott
7Stanley Hudson
8Phyllis Vance
9Angela Martin
10Oscar Martinez

Here's a working formula to get 5 items from a list in a row:

=TRANSPOSE( ARRAY_CONSTRAIN( SORT( TRANSPOSE( FILTER(A2:A, A2:A<>"")), RANDARRAY( COUNTA(A2:A),1), TRUE), 5, 1))

Notice that before the SORT can take place the data must be TRANSPOSED into a column and then TRANSPOSED back into a row at the end.

And lastly, here's a working formula to get 5 items from a list in a table:

=ARRAY_CONSTRAIN( SORT( FILTER( FLATTEN(A2:C5), FLATTEN(A2:C5)<>""), RANDARRAY( COUNTA(A2:C5), 1), TRUE), 5, 1)

Here the data is FLATTENED into a single column before being FILTERED, SORTED, and CONSTRAINED.

Randomly Select From A List With No Repeats In Google Sheets

You have a list with some items repeated.

From this list you want to get multiple items without doubling up.

To get multiple random items from this list without repeats you're going to need a slight tweak on the last formula for randomly selecting multiple items from a list.

The tweak is the inclusion of the UNIQUE function:

=UNIQUE(range)

This function takes in a range (or an array) and returns only the unique rows from that range.

If we take the formula from above (for a list in column A2:A):

=ARRAY_CONSTRAIN( SORT( FILTER(A2:A, A2:A<>""), RANDARRAY( COUNTA(A2:A), 1), TRUE), 5, 1)

You'll need to add UNIQUE at the second last step, after the data is SORTED but before it is CONSTRAINED.

Here's a working formula to get 5 unique items from a list in a column:

=ARRAY_CONSTRAIN( UNIQUE( SORT( FILTER(A2:A, A2:A<>""), RANDARRAY( COUNTA(A2:A), 1), TRUE)), 5, 1)

Here's an example (click the checkbox to refresh the volatile RANDARRAY function):

ABC
1ListFormulaOutput
2Michael Scott=ARRAY_CONSTRAIN( UNIQUE( SORT( FILTER(A2:A, A2:A<>""), RANDARRAY( COUNTA(A2:A), 1), TRUE)), 5, 1)Pam Beesly
3Michael ScottOscar Martinez
4Dwight SchruteDwight Schrute
5Dwight SchruteMichael Scott
6Jim HalpertAndy Bernard
7Jim Halpert
8Pam Beesly
9Andy Bernard
10Oscar Martinez

Here's a working formula to get 5 unique items from a list in a row:

=TRANSPOSE( ARRAY_CONSTRAIN( UNIQUE( SORT( TRANSPOSE( FILTER(A2:A, A2:A<>"")), RANDARRAY( COUNTA(A2:A),1), TRUE)), 5, 1))

And lastly, here's a working formula to get 5 unique items from a list in a table:

=ARRAY_CONSTRAIN( UNIQUE( SORT( FILTER( FLATTEN(A2:C5), FLATTEN(A2:C5)<>""), RANDARRAY( COUNTA(A2:C5), 1), TRUE)), 5, 1)

hand pointing emoji hand pointing emoji

FREE RESOURCE

Google Sheets Cheat Sheet

12 exclusive tips to make user-friendly sheets from today:

Google Sheets Cheat Sheet

You'll get updates from me with an easy-to-find "unsubscribe" link.

Kieran Dixon started using spreadsheets in 2010. He leveled-up his skills working for banks and running his own business. Now he makes Google Sheets and Apps Script more approachable for anyone looking to streamline their business and life.

Want Better-Looking Google Sheets?

Google Sheets Cheat Sheet

Get my 12-tip cheat sheet that will make your spreadsheets more user-friendly.

You'll get updates from me with an easy-to-find "unsubscribe" link.

🗙