Lesson 50 of 92 · Free Excel Course
Excel
Generate Random Numbers in Excel: RAND, RANDBETWEEN, RANDARRAY and No Duplicates
Make random numbers, dates and picks in Excel with RAND, RANDBETWEEN and RANDARRAY, avoid duplicates, shuffle a list, and freeze results. Free workbook.
Excel can roll dice, pick a raffle winner, shuffle a list of names, or fill a sheet with test data in a second. Three functions do the work: RAND for decimals, RANDBETWEEN for whole numbers and RANDARRAY for many values at once. This lesson shows each one, then the jobs people actually need: random numbers in a range, no duplicates, a random pick from a list, random dates and times, shuffling, and freezing the results so they stop changing. Every formula is in the free practice workbook.
RAND, RANDBETWEEN and RANDARRAY at a glance
| Function | What it returns | Example | Works in |
|---|---|---|---|
RAND() | A decimal, at least 0 and less than 1 | =RAND() → 0.6183 | All versions |
RANDBETWEEN(bottom, top) | A whole number from bottom to top, both included | =RANDBETWEEN(1,6) → 4 | All versions |
RANDARRAY([rows], [columns], [min], [max], [whole_number]) | A block of random numbers that spills into nearby cells | =RANDARRAY(5,1,1,100,TRUE) | Microsoft 365, Excel 2021 and later, Excel for the web |
All of RANDARRAY's arguments are optional. Leave them all out and you get one decimal between 0 and 1, like RAND. Min and max default to 0 and 1, and whole_number defaults to FALSE (decimals); type TRUE for whole numbers. If min is bigger than max, you get #VALUE!.
All three are the same on Windows, Mac and Excel for the web.
Make your first random numbers
Open the Practice sheet of the workbook:
- Click D2, type
=RAND()and press Enter. You see a decimal such as 0.6183. - In D3 type
=RANDBETWEEN(1,6). That's a dice roll. - Press F9. Both numbers change. Press it again: new numbers again.
- Type anything in an empty cell and press Enter. They change again.
| C | D | |
|---|---|---|
| 1 | Task | Result |
| 2 | Random decimal, 0 to 1 | 0.6183 |
| 3 | Dice roll, 1 to 6 | 4 |
| 4 | Decimal between 10 and 20 | 13.48 |
| 5 | Random winner from A2:A11 | Dana |
| 6 | Random date in 2027 | 7/2/2027 |
| 7 | Random time, 9 AM to 5 PM | 1:47 PM |
Why random numbers keep changing
RAND, RANDBETWEEN and RANDARRAY are volatile: Excel recalculates them every time the sheet recalculates. That happens when you enter or edit anything in any cell, when you press F9, and when you open the file. So a "winner" you picked a minute ago is gone as soon as you type in another cell.
That's useful for simulations (press F9 to run again), but annoying when you want to keep a result. You have three options:
- Freeze the values (next section). Best for most people.
- Switch to manual calculation: on Windows, Formulas > Calculation Options > Manual; in Excel for the web, the same menu on the Formulas tab. Numbers then change only when you press F9. On Windows this setting applies to every open workbook, so remember to switch it back to Automatic, or other formulas will look stuck.
- Shift+F9 recalculates only the active sheet, if you want to re-roll one sheet in manual mode.
Freeze random numbers: Paste Values or F9
To keep a set of results, swap the formulas for their values:
- Select the cells (for example D2:D7) and press Ctrl+C (Cmd+C on a Mac).
- Without moving, click Home > Paste (the arrow below the button) > Values. In Excel for the web it's Home > Paste > Paste Values.
- Press F9. The frozen cells stay put.
The keyboard route on Windows is Ctrl+Alt+V, then V, then Enter (Paste Special > Values).
To freeze just one cell, click it, press F2 to edit, press F9, then Enter. F9 inside the formula bar calculates the formula and replaces it with its result. Press Esc instead of Enter if you change your mind.
Once frozen, the formula is gone. Keep a copy of the live formula somewhere (the workbook's Answers sheet does) so you can draw again later.
Random decimals and whole numbers in any range
For a decimal between two numbers, scale RAND: =RAND()*(max-min)+min.
- Between 10 and 20:
=RAND()*(20-10)+10 - A price between $5 and $50:
=ROUND(RAND()*(50-5)+5,2)rounds it to cents.
RAND never returns exactly 1, so this gives at least 10 but less than 20. For whole numbers, use RANDBETWEEN rather than wrapping RAND in INT: =INT(RAND()*(20-10)+10) can never return 20, while =RANDBETWEEN(10,20) can.
For a whole block, use RANDARRAY. In G2 type =RANDARRAY(5,1,1,100,TRUE): five whole numbers from 1 to 100 spill down into G2:G6. =RANDARRAY(5,3,10,20) fills a 5-by-3 block with decimals between 10 and 20. If you see #SPILL!, something is in the way; clear the cells below.
Random numbers without duplicates
RANDBETWEEN and RANDARRAY can repeat a number, just like rolling a die twice. To get numbers that never repeat, shuffle a list instead of drawing from it.
Excel 365 or 2021 and later: in H2 type =SORTBY(SEQUENCE(10),RANDARRAY(10)). SEQUENCE(10) makes 1 to 10, RANDARRAY(10) makes ten random decimals, and SORTBY puts the numbers in the order of those decimals. You get 1 to 10 in a random order, each exactly once.
To keep only the first few, wrap it in TAKE (Microsoft 365 and Excel 2024): =TAKE(SORTBY(SEQUENCE(50),RANDARRAY(50)),6) gives six different numbers from 1 to 50, like a lottery draw.
Older Excel (2019 and earlier): use a helper column.
- In K2 type
=RAND()and copy it down to K11. - In L2 type
=RANK.EQ(K2,$K$2:$K$11)and copy it down. Each row gets a rank from 1 to 10. - In M2 type
=INDEX($A$2:$A$11,L2)and copy it down. Column M is the name list in random order.
| K | L | M | |
|---|---|---|---|
| 1 | Helper =RAND() | Rank | Shuffled (older Excel) |
| 2 | 0.6183 | 4 | Dana |
| 3 | 0.0942 | 10 | Jack |
| 4 | 0.8817 | 2 | Ben |
| 5 | 0.3305 | 7 | Gus |
| 6 | 0.7461 | 3 | Chloe |
Pick a random item or winner from a list
Names are in A2:A11. In D5 type:
=INDEX(A2:A11,RANDBETWEEN(1,ROWS(A2:A11)))
ROWS counts the names (10), RANDBETWEEN picks a position from 1 to 10, and INDEX returns the name at that position. Each name has the same chance. If you add names to the bottom, use =INDEX(A:A,RANDBETWEEN(2,COUNTA(A:A))), with a heading in A1 and no blank cells in the column.
For several winners with no repeats (Microsoft 365 or Excel 2024, because of TAKE), shuffle the names and take the top three: =TAKE(SORTBY(A2:A11,RANDARRAY(ROWS(A2:A11))),3). Drop the TAKE to shuffle the whole list (that's in I2 of the workbook). Freeze the result with Paste Values straight away, and take a screenshot if you need proof of a fair draw.
Random dates and times
Excel stores dates as whole numbers and times as fractions of a day, so random dates are just random numbers:
- A date in 2027:
=RANDBETWEEN(DATE(2027,1,1),DATE(2027,12,31)). If you see a number like 46570, format the cell as a date (see dates and times). - A time between 9 AM and 5 PM:
=TIME(9,0,0)+RAND()*(TIME(17,0,0)-TIME(9,0,0)), formatted as a time. - A date and time together: add the two.
- A random weekday only:
=WORKDAY(DATE(2026,12,31),RANDBETWEEN(1,261))picks one of the 261 Monday-to-Friday dates in 2027 (holidays aren't skipped unless you add a holiday list).
Handy random formulas
A few more one-liners that people search for:
| You want | Formula |
|---|---|
| Heads or tails | =IF(RAND()<0.5,"Heads","Tails") |
| Roll two dice and add them | =RANDBETWEEN(1,6)+RANDBETWEEN(1,6) |
| A random capital letter A to Z | =CHAR(RANDBETWEEN(65,90)) |
| One of a few fixed choices | =CHOOSE(RANDBETWEEN(1,3),"Red","Green","Blue") |
| A random 4-digit PIN for a game | =TEXT(RANDBETWEEN(0,9999),"0000") |
Two dice added together aren't the same as =RANDBETWEEN(2,12): a 7 comes up six times as often as a 2 with real dice, while RANDBETWEEN makes every total equally likely. Pick the formula that matches what you're simulating. And the "PIN" is for games and test data only, for the reason in the FAQ.
Try it yourself
Download the practice workbook. Your results won't match anyone else's, so the workbook also has a Frozen example sheet: one set of results saved as values, with checks that prove each rule (right count, inside the range, whole numbers, no duplicates).
- On Practice, fill D2:D7 with RAND, RANDBETWEEN, the 10-to-20 formula, the random winner, a random date and a random time.
- Press F9 a few times and watch everything change.
- Fill G2, H2 and I2 with the RANDARRAY and SORTBY formulas (Excel 365 or 2021 and later) and J2 with the TAKE formula (Microsoft 365 or Excel 2024).
- Build the older-Excel shuffle in K2:M11.
- Freeze D2:D7 with Paste Values, then press F9 to prove they stay.
- Open Frozen example. Every check in column H says TRUE. The no-duplicates check is
=SUMPRODUCT(COUNTIF(A3:A12,A3:A12))=10: each number counts itself once, so the total is 10 only if nothing repeats.
| G | H | |
|---|---|---|
| 2 | Rule | Check |
| 3 | Shuffle: 10 numbers | TRUE |
| 4 | Shuffle: none below 1 | TRUE |
| 5 | Shuffle: none above 10 | TRUE |
| 6 | Shuffle: no duplicates | TRUE |
| 7 | Shuffle: all whole numbers | TRUE |
| 8 | RANDBETWEEN: between 1 and 100 | TRUE |
Common mistakes
- Expecting the numbers to stay. They change on every edit. Freeze them with Paste Values.
- Using RANDBETWEEN when you need no repeats. It can draw the same number twice. Shuffle with SORTBY or the RANK helper.
- Wrong upper limit in a random pick.
=INDEX(A2:A11,RANDBETWEEN(1,12))sometimes returns #REF! because there are only 10 names. Use ROWS. - Blank cells with COUNTA. COUNTA skips blanks, so the last names can never win. Remove the gaps.
- Leaving calculation on Manual. Other formulas stop updating. Switch back to Automatic.
- Using RAND for security. RAND is pseudo-random and fine for games and samples, but not for passwords, codes or anything that must be unpredictable.
- RANDARRAY in an older Excel. Excel 2019 and earlier show #NAME?. Use RANDBETWEEN or the helper-column method.
What's next
You can now generate random numbers, dates and picks, shuffle a list without repeats and lock in the results. The previous lesson, CAGR and growth rates, covered yearly growth and projections. Next up is ISBLANK and logic checks. Or go back to the full Excel course to review any lesson. The SEQUENCE function page covers SEQUENCE on its own, beyond shuffling.
Frequently asked questions
How do I generate a random number in Excel?
For a whole number, type =RANDBETWEEN(1,100) and press Enter: you get a random whole number from 1 to 100, both ends included. For a decimal between 0 and 1, use =RAND(). For a decimal between two numbers, use =RAND()*(max-min)+min, for example =RAND()*(20-10)+10. In Excel 365 or 2021 and later, =RANDARRAY(10,1,1,100,TRUE) fills ten cells at once.
How do I stop random numbers from changing in Excel?
Turn the formulas into plain values. Select the cells, press Ctrl+C, then choose Home > Paste > Paste Values (or press Ctrl+Alt+V, then V and Enter). For a single cell, click it, press F2, press F9 and then Enter: the formula is replaced by its current result. Until you do that, every edit anywhere in the workbook picks new numbers.
How do I generate random numbers without duplicates in Excel?
Shuffle a list instead of drawing numbers. In Excel 365 or 2021 and later, =SORTBY(SEQUENCE(10),RANDARRAY(10)) gives the numbers 1 to 10 in a random order, so none can repeat. In Microsoft 365 or Excel 2024, wrap it in TAKE to keep the first few: =TAKE(SORTBY(SEQUENCE(50),RANDARRAY(50)),6) gives 6 different numbers from 1 to 50. In older Excel, put =RAND() in a helper column and use RANK.EQ on it.
How do I pick a random name from a list in Excel?
Use INDEX with RANDBETWEEN: =INDEX(A2:A11,RANDBETWEEN(1,ROWS(A2:A11))). ROWS counts the names, so every one has the same chance. If the list grows, use =INDEX(A:A,RANDBETWEEN(2,COUNTA(A:A))) with a heading in A1 and no blank cells. To pick several winners with no repeats, shuffle the list with SORTBY and RANDARRAY and take the top ones.
What's the difference between RAND and RANDBETWEEN?
RAND takes no arguments and returns a decimal that's at least 0 and less than 1. RANDBETWEEN(bottom, top) returns a whole number between two numbers you choose, including both of them. Both change every time the sheet recalculates. RANDARRAY does either job for many cells at once.
Is Excel's RAND truly random?
No computer formula is truly random: RAND is a pseudo-random generator, good enough for games, samples, shuffles and simulations. Don't use it for passwords, security codes or anything where someone could gain by predicting the numbers, and for prize draws with legal rules, use the method the rules require.