Sort by Random - How to Randomize the Order of Rows in Google Sheets

Introduction

Sometimes you need to shuffle or randomize rows in Google Sheets β€” for example, to create a random list of participants, shuffle quiz questions, or fairly distribute tasks. In this tutorial, you’ll learn how to randomize the order of rows in Google Sheets using simple built-in formulas and sorting features.

Step 1: Using the RAND Function

The easiest way to randomize rows is to use the RAND() function. This function generates a random decimal number between 0 and 1 each time the sheet recalculates.

Follow these steps:

  1. Insert a new column next to your data (for example, Column A is data, Column B is for random numbers).
  2. In the first cell of the new column (e.g., B2), type:
  3. =RAND()
  4. Press Enter. You will see a random number between 0 and 1.
  5. Copy this formula down the column to match all your data rows.

Now, every row has a random number assigned to it.

Step 2: Sort Rows by the Random Numbers

Once the random numbers are in place, you can shuffle the rows:

  1. Select all your data, including the column with random numbers.
  2. Go to Data > Sort range.
  3. Make sure Data has header row is checked if you have headers.
  4. Sort by your random number column in A β†’ Z order.
  5. Click Sort β€” your rows are now randomized!

Step 3: Keep the Random Order Static

If you leave the RAND() function in the sheet, every edit will re-randomize the numbers, changing the order of your rows. If you want to keep the current order:

  1. Select the column with the random numbers.
  2. Copy it (Ctrl+C or Cmd+C).
  3. Right-click and choose Paste special > Paste values only.
  4. Now the numbers are fixed, and the order won’t change unless you re-generate new random numbers.

Step 4: Using SORT with RAND in a Formula

You can also randomize rows dynamically without adding a helper column, by combining SORT() and RANDARRAY().

Example:

=SORT(A2:A10, RANDARRAY(ROWS(A2:A10)), TRUE)
  • A2:A10 β†’ Range of data you want to shuffle.
  • RANDARRAY(ROWS(A2:A10)) β†’ Generates a random number for each row.
  • TRUE β†’ Sorts in ascending order.

This creates a new randomized list without altering your original data.

Step 5: Randomizing with Google Apps Script (Optional)

If you frequently shuffle rows, you can use a Google Apps Script to automate it:

function randomizeRows() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var range = sheet.getDataRange();
  var values = range.getValues();

  // Keep header row
  var header = values.shift();
  
  // Shuffle the rows
  for (var i = values.length - 1; i > 0; i--) {
    var j = Math.floor(Math.random() * (i + 1));
    var temp = values[i];
    values[i] = values[j];
    values[j] = temp;
  }
  
  // Write back shuffled data
  values.unshift(header);
  range.setValues(values);
}
        

This script will shuffle all rows in your sheet while keeping the first row (headers) in place.

Conclusion

Randomizing rows in Google Sheets can be done easily using the RAND() function with sorting, the SORT() + RANDARRAY() formula for dynamic results, or Google Apps Script for automation. Whether you need to shuffle participants, randomize assignments, or create a new order for tasks, these methods make it quick and simple.