In Google Sheets, you can easily pick a random name from a long list using formulas or Apps Script. Whether you need a random student picker, giveaway winner selector, or team assignment tool, this tutorial explains both dynamic and static methods step by step.
It’s easy to pick a random name from a long list in Google Sheets using built-in formulas. However, while formulas are convenient, they can sometimes return different results every time the sheet recalculates because they use volatile functions.
In other words, whenever you edit the sheet or reload it, the randomly selected name may change. If you need a static (fixed) random result, Apps Script is a better solution.
Step-by-Step Instructions
Let’s assume you have a long list of student names in column A (A2:A) in Google Sheets, where A1 contains the header. Your goal is to pick a random name from the list.
Formula to Pick a Random Name in Google Sheets
You can use the following formula to select a random name from the range:
=SORTN(TOCOL(A2:A, 1), 1, 0, RANDARRAY(ROWS(TOCOL(A2:A, 1))), TRUE)
How This Formula Works
TOCOL(A2:A, 1)→ Removes empty cells from the list- The second argument (
1) tellsSORTNto return only one random name - The third argument (
0) keeps the default duplicate handling behavior RANDARRAY(ROWS(TOCOL(A2:A, 1)))→ Generates random numbers for sortingTRUE→ Sorts in ascending order based on random values
In short:
SORTN sorts the list using randomly generated values and returns the first result.
To Get 5 Random Names
Simply change the second argument in SORTN:
=SORTN(TOCOL(A2:A, 1), 5, 0, RANDARRAY(ROWS(TOCOL(A2:A, 1))), TRUE)
Limitation of the Formula
The main issue with this approach is that it is volatile.
Since RANDARRAY is a volatile function, the selected random name changes whenever the spreadsheet recalculates, such as when:
- you edit a cell
- reload the sheet
- make structural changes to the spreadsheet
So, you will not get a fixed result.
Also, if your source list contains duplicate names, both the formula and script methods may return duplicates because each row is treated as a separate entry.
How to Keep the Random Name Static
If you want the selected random names to remain unchanged, you should use Apps Script.
This is especially useful when you want:
- a random student picker
- a winner selection tool
- a task assignment system
Step 1: Create a Drop-Down Control
To control when random selection happens:
- Go to cell
B3 - Click Insert → Drop-down
- Set options:
- Yes
- No
- Click Done

Alternatively, you can use:
@ → Drop-downs → Yes/No
This will act as a trigger for generating random names.
Step 2: Add Apps Script
Go to:
Extensions → Apps Script
Replace the existing code with:
function onEdit(e) {
const sheet = e.source.getActiveSheet();
const range = e.range;
const targetSheetName = "Sheet1";
const dropdownCell = "B3";
const outputStartCell = "C2";
const numNamesToReturn = 1;
if (sheet.getName() !== targetSheetName) return;
if (range.getA1Notation() !== dropdownCell) return;
const value = range.getValue();
const outputCell = sheet.getRange(outputStartCell);
const startRow = outputCell.getRow();
const startCol = outputCell.getColumn();
const lastRow = sheet.getLastRow();
// Helper to safely clear old output down to the last data row
const clearOldOutput = () => {
if (lastRow >= startRow) {
sheet.getRange(startRow, startCol, lastRow - startRow + 1, 1).clearContent();
}
};
if (value !== "Yes") {
clearOldOutput();
return;
}
if (lastRow < 2) return;
const names = sheet
.getRange(2, 1, lastRow - 1, 1) // A2:A(lastRow)
.getValues()
.flat()
.filter(v => v !== "");
if (names.length === 0) return;
// shuffle
for (let i = names.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[names[i], names[j]] = [names[j], names[i]];
}
const selected = names
.slice(0, numNamesToReturn)
.map(v => [v]);
// Clear ALL previous output data first so no leftovers remain
clearOldOutput();
// Write new values
sheet.getRange(startRow, startCol, selected.length, 1).setValues(selected);
}
Step 3: Save the Project
Rename your project to something like:
randomname
Then click Save.
How the Script Works
The script runs automatically whenever cell B3 is edited.
- When the drop-down value is
Yes, the script randomly selects names from column A - The selected names are displayed in column C
- When the drop-down value is
No, the output is cleared

To Get 5 Random Names Using Apps Script
Change:
const numNamesToReturn = 1;
to:
const numNamesToReturn = 5;
Sample Sheet
You can use the sample sheet with the script and drop-down already set up.
Simply replace the names in column A, then toggle the Yes/No drop-down in cell B3 to generate random selections.
Conclusion
Using formulas is the quickest way to pick a random name in Google Sheets, but the results change whenever the sheet recalculates. If you need a fixed random selection, Apps Script provides a more reliable solution for student pickers, giveaways, and automated assignments.
Thanks! your article saved me a lot of time!
Thanks a lot! Your formula was very simpler compared to the one I found from another site. However, on that site, I learned I can simply press Ctrl+R to generate another name.
Hi there,
This is a great article! I’m having an issue where I have more than one of these in the same sheet and when I change one, the other formula resets. How do I make sure that changing one Yes to No doesn’t affect the other formula?
Thanks!
Hi, Casey,
Seems you want to pick multiple random names. So instead of keeping two lists and two formulas in the same sheet, make it as one list and use another formula.
I have another tutorial. See the second link under the related post above.
Best,
Hi,
Good day!
I tried using the formula and I am sure that I have placed them in the right cells and columns. However, the picker seems to do not stop shuffling names. It runs like a loop.
How can I control the trigger? I noticed the random value changes everytime I make any change in any other cell.
How can I use the trigger only once so that the random value does not change on any other change?
It’s not possible as RANDBETWEEN is a volatile function like
now(). There may be scripts but I am not sure.The other option is trying the “Randomise range” that you can find under the Data Menu. Select the range and apply “Randomise range”
Updated: Now It’s possible to stop refreshing the generated random name.
Hey there, this worked perfectly. Just wondering, could i change the chances of a particular name coming up?
Hi, Damon,
I think you want to deliberately exclude one name appearing in the random list. In the formula replace the range A2: A (both in Index and Counta) with the filter formula as below.
filter(A2:A,A2:A<>"the name to exclude")See if this works.
Thank you for writing such an useful article. I am getting parse error whenever I try use function below in my google spreadsheet.
=if(B3=”Yes”,iferror(index(A2:A,randbetween(1,counta(A2:A))),”No Name!”),””)
It would be very helpful if you can help me in solving this problem.
Thank you in advance.
Hi Ashish,
If you copy my formula, you should retype all the double quotes in the formula. Because I’ve pasted the formulas in my post as blockquotes.
Now I’ve modified it as a code. Either retype the double quotes or copy the formula again from my page.
Hope this may solve the problem.
How do i prevent the the random name generator from using the same names more than once?
Hi,
Please see if this is working!
Randomly Select Unique N numbers