Skip to content

RAND

Returns a random decimal from 0 up to, but not including, 1. It gives a new number every time the sheet recalculates.

Syntax

=RAND()

Math and trigonometry

All versions of Excel.

Try it

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

A2
A
B
C
1
Check
2
0
3

A2 =INT(RAND()) returns 0

How RAND works

RAND returns a random decimal that is at least 0 and less than 1. It takes no arguments, but the brackets are required: =RAND(). Every time the workbook recalculates, every RAND cell gets a new value.

Volatile: it changes constantly

RAND is a volatile function. Excel recalculates it whenever anything on the sheet changes, when you press F9, and when the workbook opens. That is what you want for simulations, but it is a problem when you need a number that stays put. To freeze random numbers, copy the cells and use Paste Special > Values, which replaces the formulas with the numbers they showed. Keep the formulas somewhere else if you may need a fresh draw.

Because the value is different each time, the examples on this page test properties that always hold, such as "the result is between 0 and 1", rather than showing a particular value.

Scaling and shifting

A number from 0 up to but not including 1 can be stretched to any range:

  • A decimal between a and b: =a + RAND() * (b - a). For 5 to 10: =5 + RAND()*5.
  • A whole number from 1 to 6: =INT(RAND()*6) + 1. INT cuts the decimals off, so 0.999 times 6 becomes 5, plus 1 gives 6.
  • A yes or no with a given chance: =IF(RAND()<0.3, "Yes", "No") says Yes about 30% of the time.
  • A coin flip: =IF(RAND()<0.5, "Heads", "Tails").

For whole numbers, RANDBETWEEN is shorter. =RANDBETWEEN(1, 6) does the same as the INT formula.

Shuffling and sampling

RAND is the usual way to put a list in random order. Put =RAND() next to each item and sort by that column. In Microsoft 365, =SORTBY(A2:A9, RANDARRAY(ROWS(A2:A9))) shuffles the list without a helper column. To draw a random sample, take the first n rows of the shuffled list.

Practical points

  • The result can never be exactly 1, so INT(RAND()*n) never produces n.
  • Every RAND in a workbook is independent. Referring to one cell twice gives one value; typing RAND() twice gives two different values.
  • Large numbers of RAND cells make a workbook slow, because every volatile cell and everything that depends on it recalculates on each change.
  • RAND isn't suitable for security. It is for modelling, sampling and games.

Arguments

Examples

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

Example 1

The result is always below 1

A2 =INT(RAND())

Result: 0

RAND is 0 or more but less than 1, so INT of it is always 0. This is a repeatable way to show the range, since the number itself changes on every recalculation.

A2
A
B
C
1
Check
2
0
3

A2 =INT(RAND()) returns 0

Example 2

A random decimal inside a range

C2 =LET(r,A2+RAND()*(B2-A2),AND(r>=A2,r<B2))

Result: TRUE

The LET name r holds one random draw, which the AND then tests against both limits. The draw is different each time, but the check is always TRUE.

C2
A
B
C
D
1
Low
High
In range?
2
5
10
TRUE
3

C2 =LET(r,A2+RAND()*(B2-A2),AND(r>=A2,r<B2)) returns TRUE

Example 3

A random whole number from 1 to 6

A2 =LET(n,INT(RAND()*6)+1,AND(n>=1,n<=6,n=INT(n)))

Result: TRUE

INT(RAND()*6) is 0 to 5, so adding 1 gives 1 to 6. The check confirms the roll is a whole number in range.

A2
A
B
C
1
Die roll valid?
2
TRUE
3

A2 =LET(n,INT(RAND()*6)+1,AND(n>=1,n<=6,n=INT(n))) returns TRUE

Example 4

A coin flip always returns one of two values

A2 =LET(f,IF(RAND()<0.5,"Heads","Tails"),OR(f="Heads",f="Tails"))

Result: TRUE

Each flip shows Heads or Tails at random, so the check that the flip is one of the two is always TRUE. LET holds a single flip for both tests.

A2
A
B
C
1
Matches
2
TRUE
3

A2 =LET(f,IF(RAND()<0.5,"Heads","Tails"),OR(f="Heads",f="Tails")) returns TRUE

Example 5

Shuffle a list: the shuffled list has the same size

B8 =ROWS(SORTBY(A2:A6,RANDARRAY(ROWS(A2:A6))))

Result: 5

The order of the five names is random each time, but there are always five. SORTBY with a column of random numbers is the formula-only way to shuffle.

B8
A
B
C
1
Name
2
Aro
3
Bex
4
Cal
5
Dee
6
Eli
7
8
Rows after shuffle
5

B8 =ROWS(SORTBY(A2:A6,RANDARRAY(ROWS(A2:A6)))) returns 5

Your turn.

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

Task 1 of 2

In D2, roll a die with the number of sides in B2: a random whole number from 1 to B2. Show TRUE if the roll is a whole number between 1 and B2.

Answer in D2.

D2
A
B
C
D
1
Names
Max roll
Check
2
Aro
6
3
Bex
4
Cal
5
Dee
6
Eli
7

Common mistakes

  • RAND changes on every recalculation, including when you edit an unrelated cell. If a result must stay fixed, paste it as values.
  • Pasting values over RAND loses the formula. Keep a copy if you may need a new draw.
  • Don't type RAND without brackets. =RAND is #NAME?; the function needs RAND().
  • Calling RAND twice in one formula gives two different numbers. To use one draw twice, store it in a cell, or in a LET name.
  • Lots of RAND cells slow a big workbook down, because they recalculate on every change.

Questions people ask

How do I stop RAND from changing?

Copy the cells, then use Paste Special > Values. The formulas are replaced by the numbers they showed, and those numbers no longer change. Setting calculation to manual only delays the next change.

How do I generate a random number between two values?

Use `=low + RAND()*(high-low)` for a decimal, or `=RANDBETWEEN(low, high)` for a whole number.

Can RAND return 1?

No. The result is at least 0 and less than 1. That is why `INT(RAND()*6)+1` gives 1 to 6 and never 7.

How do I shuffle a list in Excel?

In Microsoft 365, use `=SORTBY(A2:A9, RANDARRAY(ROWS(A2:A9)))`. In other versions, put RAND() beside each item and sort the list by that column.

What is the difference between RAND and RANDBETWEEN?

RAND returns a decimal from 0 up to 1. RANDBETWEEN returns a whole number between two numbers you choose, inclusive.

Learn RAND in a real sheet.

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