How to Randomly Select N Numbers from a Column in Google Sheets

I want to Randomly Select N Numbers from a column. What’s the solution? In Google Sheets, you can use my formula to pick a set of random numbers or names from a column. The formula is the same for numbers, names and even dates.

You will find the below Random Selector formula very useful. With the help of my formula, you can do the following and more.

  1. Pick a group of players randomly.
  2. Randomly select students for different divisions.
  3. Pick N number of winners in a lottery.
  4. Exclude excess people randomly when you have limited Quota.

The Formula to Randomly Select N Numbers from a Column in Google Sheets

I can tell you how to use this formula to randomly select N numbers or names from a Column in Google Doc Sheets. You should make two changes in the formula to suits your purpose.

Master Formula:

=ArrayFormula(Array_Constrain(vlookup(Query({ROW(A1:A20),randbetween(row(A1:A20)^0,9^9)},"Select Col1 order by Col2 Asc"),{row(A1:A20),A1:A20},2,FALSE),10,1))

What are those changes?

  1. The above formula is for the range A1:A20. For example, if you want to use this formula in a larger list of 400 rows, change the range in the formula A1:A20 to A1: A400.
  2. This master formula randomly picks 10 numbers or names from column A. The number 10 at the last part of the formula indicates the number of random numbers or names to be returned. You can change that number.

For example, if your range is A1:A100 and if you set the above-said number 10 to 50, the formula would return 50 random names or numbers. If you set it to 100, it would just shuffle your values in the range A1:A100 and return all the hundred numbers or names.

Example: Pick 10 Random Names Out of 20 Names

The above formula in C1 has randomly selected 10 names from column A.

Example to Pick 10 Random Names Out of 20

Formula Explanation

This section is useful if you want to know how the master formula above picks N’ number of Random items in Google Sheets.

Note: You can learn a lengthy formula by looking at the middle part of it. Any nested spreadsheet formula would normally develop from the middle. I am following this method to explain to you the above formula.

No doubt, without the function RANDARRAYRANDBETWEEN or RAND we can’t pick random names or numbers in Google Sheets. In the above formula, I’ve used the RANDBETWEEN function.

RANDBETWEEN(LOW, HIGH)

Suppose your “low” value is 1 and “high” value is 20, this function would return a random number between 1 and 20, both the numbers inclusive.

For my formula purpose, I want to generate 20 random numbers. What’s the option? By default, there is no option. But you can tweak the RANDBETWEEN as below.

The breakup 1:

=ArrayFormula(randbetween(row(A1:A20)^0,9^9))

No doubt. Here we can apply a common practice that all the Google Sheets’ experts follow. That is feeding the “low” argument with the Row function =ArrayFormula(row(A1:A20)) can return the numbers (not random numbers) 1 to 20. Since I have chosen 0 as the power (^0) the formula returns the number 1, 20 times.

The “high” value is set to 9^9 that is equal to 387420489.

So the above example formula would return 20 unique random numbers between 1 to 9^9.

I can use any number like 100, 200, etc. instead of 9^9 in the RANDBETWEEN formula as the “high” argument. But a large number can ensure that the formula is not returning any duplicate values.

The output of the above RANDBETWEEN formula would be something like below (the numbers won’t be the same).

10 unique random numbers in Google Sheets

The breakup 2:

Here we are adding additional functions to the “breakup 1” formula.

=ArrayFormula(Query({ROW(A1:A20),randbetween(row(A1:A20)^0,9^9)},"Select Col1 order by Col2 Asc"))

Actually, I don’t want the above generated (please see the screenshot) random numbers. What I want is to generate a set of random numbers between 1 to 20. To do that I’ve virtually created a two column array.

See the above “breakup 2” formula. The first column is the serial numbers 1 to 20 returned by a ROW function and the second column is the above 20 numbers returned by the “breakup 1” formula.

These columns used as the range in Query and sorted the column 1 based on column 2 and limited the column output to 1.

The Query formula does this part. Now I have got a column with random numbers 1 to 20. I mean the number 1 to 20 in random order.

The breakup 3:

The below formula is the combination of the breakup 1 and 2 formulas above.

=ArrayFormula(vlookup(Query({ROW(A1:A20),randbetween(row(A1:A20)^0,9^9)},"Select Col1 order by Col2 Asc"),{row(A1:A20),A1:A20},2,FALSE))

This formula uses Vlookup to pick random names from Column A which is our goal.

VLOOKUP(SEARCH_KEY, RANGE, INDEX, [IS_SORTED])

Here the search_key is the above “breakup 2” formula which generates random numbers from 1 to 20.

The range should be our list of names in Column A1: A20. But we can’t use this since our search_key is the random numbers from 1 to 20.

Here again, I’ve generated a two column array. The first column is the row numbers 1 to 20 and the second column is the actual values (names) in column A1:A20.

The column index is 2 in the Vlookup. So the Vlookup function will use the search key (random numbers from 1 to 20) to search the first column in the range (numbers 1 to 20 in order) and return the names from column 2 if a match found.

This formula will return all the names in a random order. You can wrap this formula with the Array_Constrain to return the total random names as per your desired number, here 10. That is what I’ve done in my final formula.

That’s all. Whenever you want to pick some names or numbers randomly, use my formula.  Also, I hope you could learn the steps to generate the formula that randomly selects N numbers from a column in Google Sheets.

Related Reading:

  1. Google Sheets: Macro-Based Random Name Picker.
  2. How to Pick a Random Name from a Long List in Google Sheets.
  3. How to Shuffle Rows in Google Sheets Without Plugin
Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Lookup Previous Values Dynamically in Excel and Google Sheets

Sometimes, you may want to look up the previous values relative to the current...

Sort Data but Keep Blank Rows in Excel and Google Sheets

Using a dynamic array formula or the FILTER command, we can sort data and...

Lookup Values Under Categories in Excel and Google Sheets

We can use a combination of XLOOKUP and VLOOKUP in both Excel and Google...

Extract Items Under a Category from the Same Column in Excel

In Excel, you can use a combination of the XLOOKUP and DROP functions to...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

6 COMMENTS

  1. Excellent article and explanation, thank you very much! But the formula came back #Error in my Spreadsheets. Do you help me with any solution?

  2. Hi Prashanth! Thank you so much for this equation. I’m about 95% through my project, thanks to this. I have a question, though.

    Are you able to insert a FILTER function into this equation? Say, for instance, I had a large data set to apply your equation to, but only wanted to pull random numbers that met certain conditions:

    So, instead of your fixed range, (A1:A20), let’s say I wanted to do something like FILTER(A2:A,A2:A$D3) . . . where D=100;

    FILTER(A2:A,A2:A>$D4) . . . where D=500, etc.

    So I was hoping the filter function could be integrated into your master formula:

    Any suggestions?

    Thanks in advance!

      • Hi, Stephen,

        For this, I am going to provide you a different formula. If that doesn’t help, please share an example sheet with me in reply.

        Google Sheets has now a more convenient formula to generate random numbers in an array form and that is RANDARRAY. I am going to use that here in SORTN.

        =SORTN(FILTER(A1:A,A1:A>D3),9^9,0,randarray(COUNTA(FILTER(A1:A,A1:A>D3)),1),TRUE)

        How to use this formula?

        This filters the numbers in column A based on the value in cell D3 and randomizes the filtered output.

        The 9^9 in the formula is to return all the filtered values in random order. You can change that to any number to limit the number of rows in the output. If you set it to 10, you will get 10 random numbers. But if the filtered output doesn’t contain 10 numbers, the formula would return an error.

        To understand the formula please check the individual tutorials related to SORTN and RANDARRAY. I’ll try to write a tutorial on the combined use later.

        Best,

        Prashanth KV

  3. Hi Prashanth, fantastic article and great explanation, thanks so much! It really helped me with my research.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.