Skip to content

RANDARRAY

Returns an array of random numbers, decimals or whole numbers, in a size and range you choose. It recalculates on every change.

Syntax

=RANDARRAY(, , , , )

Dynamic arrays

Excel for Microsoft 365, Excel 2021 and later, and Excel for the web. Not available in Excel 2019 or earlier.

Try it

Edit the formula in A1 or change the inputs. The sheet recalculates as you type.

A1
A
B
C
D
1
15
2
3
4

A1 =COUNT(RANDARRAY(5,3)) returns 15

How RANDARRAY works

RANDARRAY returns a block of random numbers from one formula. It is RAND and RANDBETWEEN with a size: you say how many rows and columns, the range, and whether you want whole numbers.

The arguments

  • rows and columns set the size of the result. Both default to 1, so =RANDARRAY() is the same as RAND.
  • min and max set the range. The defaults are 0 and 1.
  • whole_number is FALSE for decimals (the default) or TRUE for whole numbers. With TRUE, both ends of the range can be returned: =RANDARRAY(10,1,1,6,TRUE) is ten dice rolls.

It recalculates constantly

RANDARRAY is volatile. It produces new numbers every time the worksheet recalculates, which means after nearly any edit anywhere in the workbook, and each time you press F9. That is the point when you want a fresh draw, and a problem when you want to keep one. To freeze a result, copy the spilled cells and use Paste Special > Values.

Because the numbers are always changing, any figure built from RANDARRAY on its own changes too. When you test a formula that uses it, check things that stay true on every draw: the size of the result, that every value falls in the range, or that a shuffled list still adds up to the same total. The examples below do exactly that.

Shuffling and random picks

The most useful job for RANDARRAY is putting a list in random order. Sort the list by a column of random numbers:

=SORTBY(A2:A7,RANDARRAY(ROWS(A2:A7)))

Every recalculation gives a new order, but the list always contains the same items. Wrap it in TAKE to pick random winners: =TAKE(SORTBY(A2:A20,RANDARRAY(ROWS(A2:A20))),3) returns three different names. RANDBETWEEN can return the same number twice. A shuffle can't.

Test data

For quick sample data, use =RANDARRAY(20,1,500,2000,TRUE) for twenty whole-number amounts, or =RANDARRAY(12,1,0.02,0.08) for twelve rates between 2% and 8%.

Spilling

The result spills into the cells below and to the right of the formula. If something occupies those cells, you get #SPILL!. See FILTER for how spill ranges work and how the # operator reads one.

RANDARRAY, RAND and RANDBETWEEN

RAND returns one decimal and RANDBETWEEN one whole number, so filling a block needs the fill handle. RANDARRAY needs one formula. Use RANDBETWEEN for a single value, and RANDARRAY for a block. None of them is suitable for anything that must be repeatable or secure: you can't set a seed in Excel.

Arguments

rowsoptional
How many rows. The default is 1.
columnsoptional
How many columns. The default is 1.
minoptional
The smallest value. The default is 0.
maxoptional
The largest value. The default is 1. If it is smaller than min, RANDARRAY returns #VALUE!.
whole_numberoptional
TRUE for whole numbers, FALSE for decimals. The default is FALSE.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

How many values does a 5 by 3 array hold?

A1 =COUNT(RANDARRAY(5,3))

Result: 15

RANDARRAY(5,3) on its own fills a 5 by 3 block with different decimals each time. COUNT gives 15 every time, which is the part that never changes.

A1
A
B
C
D
1
15
2
3
4

A1 =COUNT(RANDARRAY(5,3)) returns 15

Example 2

Dice rolls always land between 1 and 6

A1 =LET(r,RANDARRAY(100,1,1,6,TRUE),AND(MIN(r)>=1,MAX(r)<=6))

Result: TRUE

LET keeps one draw of 100 whole numbers under the name r, so MIN and MAX examine the same numbers. The test is TRUE whatever the draw.

A1
A
B
C
D
1
TRUE
2
3
4

A1 =LET(r,RANDARRAY(100,1,1,6,TRUE),AND(MIN(r)>=1,MAX(r)<=6)) returns TRUE

Example 3

Decimals stay between the minimum and maximum

A1 =LET(r,RANDARRAY(4,4,50,60),AND(MIN(r)>=50,MAX(r)<=60))

Result: TRUE

Without whole_number, the values are decimals between 50 and 60. Sixteen different numbers every time, all inside the range.

A1
A
B
C
D
1
TRUE
2
3
4

A1 =LET(r,RANDARRAY(4,4,50,60),AND(MIN(r)>=50,MAX(r)<=60)) returns TRUE

Example 4

Shuffle a list: the total never changes

C2 =SUM(SORTBY(A2:A7,RANDARRAY(ROWS(A2:A7))))

Result: 770

SORTBY puts the six amounts in a new random order on each recalculation, but the same six amounts are still there. Remove the SUM and the formula spills the shuffled list instead, in a different order each time.

C2
A
B
C
D
1
Amount
2
120
770
3
85
4
240
5
60
6
175
7
90
8

C2 =SUM(SORTBY(A2:A7,RANDARRAY(ROWS(A2:A7)))) returns 770

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 3

In F1, count how many numbers a random array with D1 rows and D2 columns would hold.

Answer in F1.

F1
A
B
C
D
E
F
G
1
Amount
Rows
5
2
120
Columns
3
3
85
Low
10
4
240
High
20
5
60
6
175
7
90
8

Common mistakes

  • RANDARRAY recalculates on every change, so the numbers you looked at a moment ago are gone. Copy the result and use Paste Special > Values to keep a draw.
  • #VALUE! means max is smaller than min, or whole_number is TRUE and min or max has a decimal part. Check the order of the two limits and use whole numbers for whole results.
  • #SPILL! means the cells the array needs are not empty. Clear them or move the formula.
  • A volatile function slows a big workbook, because everything that depends on it recalculates too. Paste values once you no longer need it live.
  • Repeated values are possible. To pick distinct items from a list, shuffle it with SORTBY(list,RANDARRAY(ROWS(list))) and take the first few, instead of calling RANDBETWEEN several times.

Questions people ask

Why do my RANDARRAY numbers keep changing?

RANDARRAY is volatile, so it recalculates whenever the workbook does. To keep a set of numbers, copy them and paste as values.

How do I generate random whole numbers in Excel?

Set the fifth argument to TRUE. `=RANDARRAY(10,1,1,100,TRUE)` returns ten whole numbers between 1 and 100, both ends included.

How do I shuffle a list in Excel?

Sort the list by random numbers: `=SORTBY(A2:A20,RANDARRAY(ROWS(A2:A20)))`. Each recalculation produces a new order.

How do I pick random items from a list without repeats?

Shuffle the list and take the first few: `=TAKE(SORTBY(A2:A20,RANDARRAY(ROWS(A2:A20))),3)` returns three different items from A2:A20.

Can I set a seed to get the same numbers every time?

No. Excel has no seed option. If you need a repeatable set, generate the numbers once and paste them as values.

What is the difference between RANDARRAY and RANDBETWEEN?

RANDBETWEEN returns one whole number and has to be copied into every cell. RANDARRAY returns a whole block from one formula and can return decimals as well.

Learn RANDARRAY in a real sheet.

Tracks take you from the basics to modelling, one graded exercise at a time.