Math & trig function

RANDARRAY function

Returns a spilled array of random numbers with the size, range and type (decimal or whole) you choose.

Available in Microsoft 365, Excel 2021 and later, Excel for the web

Excel 2021 and laterDifferent in Google Sheets

Syntax

RANDARRAY([rows], [columns], [min], [max], [whole_number])
ArgumentWhat it means
rowsOptionalNumber of rows to return. Default 1.
columnsOptionalNumber of columns. Default 1.
minOptionalSmallest value. Default 0.
maxOptionalLargest value. Default 1.
whole_numberOptionalTRUE for integers, FALSE (default) for decimals.

Returns: An array of random numbers that spills into neighbouring cells.

How RANDARRAY works

RANDARRAY creates a whole block of random numbers with one formula. =RANDARRAY(5, 3) fills 5 rows by 3 columns with decimals between 0 and 1; add min, max and TRUE for whole numbers, e.g. =RANDARRAY(10, 1, 1, 6, TRUE) for ten dice rolls. It replaces dragging RAND or RANDBETWEEN formulas across a range.

As a dynamic-array function its result spills into the cells below and to the right, so they must be empty (otherwise you see #SPILL!). Like RAND it is volatile and recalculates whenever the sheet changes. A neat trick is to use it as a sort key: =SORTBY(list, RANDARRAY(ROWS(list))) returns a shuffled copy of a list. With decimals, the max value itself is never returned; with whole numbers both min and max are possible.

Examples

1A 3 × 2 block of random decimals

A1fx=RANDARRAY(3, 2)
AB
10.28410.9035
20.55170.1209
30.77630.4380

Six decimals between 0 and 1, shown with 4 decimals. Because the function recalculates whenever the sheet changes, your result will differ; the value shown is only an illustration.

2Simulate ten dice rolls

A1fx=RANDARRAY(10, 1, 1, 6, TRUE)
A
14
21
36
43
53
65
72
86
91
104

Whole numbers from 1 to 6 in a column. Because the function recalculates whenever the sheet changes, your result will differ; the value shown is only an illustration.

3Shuffle a list of names

C2fx=SORTBY(A2:A6, RANDARRAY(ROWS(A2:A6)))
ABC
1Employee
2AnaDev
3BenAna
4ChloeEma
5DevChloe
6EmaBen

Each name gets a random sort key and SORTBY orders by it, giving a random running order for presentations. Because the function recalculates whenever the sheet changes, your result will differ; the value shown is only an illustration.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 16 KB

Common errors and how to fix them

ErrorWhy it happensFix
#SPILL!Cells in the spill area are not empty.Clear the cells below/right of the formula.
#VALUE!min is larger than max, or rows/columns are 0 or negative.Check the arguments.
#NAME?Excel 2019 or older.Use RAND/RANDBETWEEN filled across the range.

Tips

  • Freeze the numbers with Copy > Paste Values.
  • Random test data for sales between 500 and 2,000: =RANDARRAY(20, 1, 500, 2000, TRUE).

Google Sheets

Google Sheets' RANDARRAY(rows, columns) only returns decimals between 0 and 1; there are no min, max or whole_number arguments, so scale with ROUND(min + RANDARRAY(r, c) * (max - min)).

RANDARRAY in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
DanishSLUMPMATRIX
DutchASELECT.MATRIX
FinnishSATUNN.MATRIISI
GermanZUFALLSMATRIX
HungarianVÉLETLENTÖMB
ItalianMATR.CASUALE
Norwegian (Bokmål)TILFELDIGMATRISE
PolishLOSOWA.TABLICA
Portuguese (Brazil)MATRIZALEATÓRIA
Portuguese (Portugal)MATRIZALEATÓRIA
SpanishMATRIZALEAT
SwedishSLUMPMATRIS
TurkishRASGDİZİ

Recipes that use RANDARRAY