Google Sheets RANDARRAY Function: Usage and Examples
In this article
The RANDARRAY function in Google Sheets generates a grid of random numbers based on a specified number of rows and columns. To use it, enter =RANDARRAY(rows, columns, min, max, integer) into a cell, where you define the size of the array and the range of the numbers you want to produce. This function is particularly useful for creating mock data, conducting randomized sampling, or building simulation models without having to drag a single formula across hundreds of cells.
What You'll Need
- A Google account with access to Google Sheets.
- A blank area of a spreadsheet (the function requires empty cells to "spill" the results into).
- A basic understanding of how rows and columns are structured in a grid.
Step-by-Step
- Identify your required grid size: Before typing the formula, determine how many rows and how many columns of random numbers you need. For example, if you need a 5x5 grid, your row value is 5 and your column value is 5.
- Select the starting cell: Click on the top-left cell where you want the random array to begin. Ensure that the cells to the right and below this cell are empty; if there is existing data in the way, Google Sheets will return a #REF! error because it cannot overwrite existing content.
- Enter the basic function: Type
=RANDARRAY(into the cell. - Define the dimensions: Enter the number of rows, followed by a comma, then the number of columns. For a 5x5 grid, it would look like
=RANDARRAY(5, 5). If you press Enter now, Google Sheets will generate a 5x5 grid of decimal numbers between 0 and 1. - Set the range (Optional): If you need numbers other than decimals between 0 and 1, add the minimum and maximum values. For example, to get numbers between 10 and 50, the formula becomes
=RANDARRAY(5, 5, 10, 50). Note that these will still be decimal numbers by default. - Force whole numbers (Optional): To ensure the function only returns integers (whole numbers), add the boolean value
TRUEas the final argument. The formula=RANDARRAY(5, 5, 10, 50, TRUE)will generate a 5x5 grid of random whole numbers between 10 and 50. - Execute the formula: Press Enter. The array will immediately populate the designated range of cells.
Common Mistakes
One of the most frequent errors users encounter is the #REF! error. This happens when the RANDARRAY function tries to output data into cells that already contain text or numbers. Because RANDARRAY is a dynamic array function, it "spills" the results. If even one cell in the target range is occupied, the entire array will fail to load. Always clear the destination area before applying the formula.
Another common mistake is confusing the row and column arguments. The syntax is strictly (rows, columns). If you intend to create a long vertical list of 10 numbers, you must enter =RANDARRAY(10, 1). Entering =RANDARRAY(1, 10) will instead create a wide horizontal row of 10 numbers.
Users also often forget that RANDARRAY is volatile. A volatile function is one that recalculates every time any change is made to the spreadsheet. If you enter a value in a completely different cell or refresh the page, all the numbers generated by RANDARRAY will change. If you need the numbers to remain static for a report or a permanent record, you must convert them to static values.
Tips
Freezing your data: To stop the numbers from changing, highlight the entire generated array, copy it (Ctrl+C or Cmd+C), then right-click the same area and select Paste special > Values only. This replaces the formula with the actual numbers it generated, preventing them from shifting during future edits.
Combining with other functions: You can wrap RANDARRAY inside other functions to create more complex tools. For example, if you want to find the highest random number in a generated set, you can use =MAX(RANDARRAY(10, 1, 1, 100, TRUE)). This generates 10 random numbers and immediately displays only the largest one.
Creating random lists: If you have a list of names in column A and want to assign a random ID number to each, use =RANDARRAY(COUNTA(A:A), 1, 1000, 9999, TRUE). By using COUNTA, the RANDARRAY automatically adjusts its height to match the number of names in your list, ensuring every person gets a unique random number without you having to manually count the rows.
Using decimals for precision: If you are simulating probability or percentages, omit the final TRUE argument. This allows you to generate high-precision floats between 0 and 1, which can then be formatted as percentages using the toolbar's percentage button.
Troubleshooting
If the function is not working as expected, follow these steps in order:
- Check for #REF! errors: If you see this error, hover your mouse over the cell. It will tell you which cell is blocking the array. Go to that specific cell, delete the content, and the array should automatically populate.
- Verify the syntax: Ensure you have used commas to separate your arguments. Using semicolons or periods will cause a formula parse error. The correct structure is
=RANDARRAY(rows, cols, [min], [max], [integer]). - Check for negative numbers: If you are trying to generate negative random numbers, ensure your
minvalue is negative (e.g.,=RANDARRAY(5, 5, -100, -1, TRUE)). If the min and max are swapped, the function may return an error or unexpected results. - Refresh the sheet: If the numbers aren't updating when you want them to, try pressing F5 to refresh the browser or enter a dummy value in an empty cell to trigger a recalculation.
Frequently Asked Questions
Can I use RANDARRAY to pick a random name from a list?
Not directly, as RANDARRAY generates numbers, not text. However, you can use it in combination with the INDEX function. For example, =INDEX(A1:A10, RANDARRAY(1, 1, 1, 10, TRUE)) will pick one random name from the range A1:A10.
Does RANDARRAY generate unique numbers?
No, it does not guarantee uniqueness. Because it is truly random, there is a possibility of duplicate numbers appearing in the array. If you need a list of unique random numbers, you should use the =SORTN(SEQUENCE(100), 10, 0, RANDARRAY(100, 1), TRUE) method or a similar combination of SORT and RANDARRAY.
What is the maximum size of an array I can generate?
While there is no specific "RANDARRAY limit," you are limited by the overall cell limit of a Google Sheet (currently 10 million cells). Generating an array that is too large (e.g., 10,000 x 10,000) may cause the browser to freeze or the sheet to crash due to memory exhaustion.
How do I make the numbers update only when I want them to?
You cannot tell a volatile function to stop updating while the formula remains active. The only way to control the update is to "freeze" the values using Paste Special > Values only. Once converted to values, they will never change unless you manually edit them.
Is RANDARRAY available in Excel too?
Yes, Microsoft Excel has a very similar RANDARRAY function available in Office 365 and Excel 2021. The syntax is nearly identical, though some behavior regarding how the array spills may vary slightly between the two platforms.