Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Can Excel Generate a Random Number? Yes, Here's How

· 6 min read · Home Tech

In this article
  1. The Core Random Number Functions
  2. How Excel's Random Numbers Actually Work
  3. Recalculation: Why Your Numbers Keep Changing
  4. Generating Random Numbers Without Duplicates
  5. Random Sampling from a List
  6. The Analysis ToolPak Alternative
  7. Common Problems and Fixes
  8. Frequently Asked Questions

Yes, Excel can generate random numbers, and it takes nothing more than a single built-in formula: typing =RAND() into any cell instantly produces a random decimal between 0 and 1, and =RANDBETWEEN(1,100) produces a random whole number between 1 and 100. No add-ins, macros, or special settings are required for the basics, and newer versions of Excel include an even more powerful function called RANDARRAY for generating whole ranges of random numbers at once.

The Core Random Number Functions

Excel ships with three functions designed specifically for generating random values:

  • RAND() returns a random decimal greater than or equal to 0 and less than 1, such as 0.428971. It takes no arguments.
  • RANDBETWEEN(bottom, top) returns a random integer between the two values you supply, inclusive. For example, =RANDBETWEEN(1,6) mimics a six-sided die.
  • RANDARRAY(rows, columns) returns an array of random decimals filling the number of rows and columns you specify. It is available in Microsoft 365 and Excel 2021 and later, and it can also take optional arguments to return integers within a range and to allow or prevent duplicate values.

Any of these can be combined with arithmetic to reshape the output. For instance, =RAND()*50+10 produces a random decimal between 10 and 60, and =ROUND(RAND()*100,0) gives a random whole number from 0 to 100, similar to RANDBETWEEN.

How Excel's Random Numbers Actually Work

Excel does not produce true randomness. Like virtually all software, it uses a pseudo-random number generator, a mathematical algorithm that starts from an internal seed value and produces a sequence of numbers that appear random and pass standard statistical tests, but are actually deterministic. For everyday purposes such as sampling, simulations, games, mock data, and classroom exercises, this is entirely sufficient. For cryptographic or security-sensitive uses, spreadsheet randomness is not appropriate.

One practical limitation worth knowing: Excel's RAND and RANDBETWEEN functions offer no way to set the seed, so you cannot reproduce the same sequence of numbers on demand using formulas alone. Users who need reproducible randomness typically record the generated values or use VBA, where the Randomize statement and Rnd function allow more control.

Recalculation: Why Your Numbers Keep Changing

RAND, RANDBETWEEN, and RANDARRAY are volatile functions. This means Excel recalculates them every time the worksheet recalculates, which happens when you edit any cell, press F9, open the file, or perform many other actions. A common surprise for new users is watching every random number on the sheet change the moment they type something unrelated elsewhere.

If you want to generate random numbers but then keep them fixed, the standard approach is to convert the formulas to static values:

  1. Select the cells containing the random formulas.
  2. Copy them with Ctrl+C (or right-click and choose Copy).
  3. Right-click the same selection and choose Paste Special, then Values (or press Ctrl+Alt+V and select Values).

The formulas are replaced by the numbers they last produced, and those numbers will no longer change.

Generating Random Numbers Without Duplicates

A frequent real-world need is a list of unique random numbers, for example to assign shuffled IDs or draw prize winners. Plain RANDBETWEEN can repeat values, so it is not the right tool on its own. Reliable methods include:

  • RANDARRAY with the unique argument: in Microsoft 365 or Excel 2021, =RANDARRAY(10,1,1,100,TRUE) returns ten unique integers between 1 and 100.
  • RANK on random decimals: fill a column with =RAND(), then use =RANK(A1,$A$1:$A$10) next to it. Because the underlying decimals are almost certainly all different, ranking them yields a unique shuffled sequence of integers.
  • Sort by a random helper column: add =RAND() beside an existing list and sort the list by that column to shuffle it randomly.

Random Sampling from a List

Choosing random entries from existing data is one of the most common uses. Given a list in cells A2:A101, you can pick one random row with =INDEX(A2:A101, RANDBETWEEN(1,100)), which picks a random position between 1 and 100 and returns whatever sits there. In Microsoft 365, the newer CHOOSEROWS and TAKE functions can be combined with RANDARRAY to pull several random rows at once. Analysts building samples from large datasets often use these techniques together with the unique-number methods above to draw a sample without repeats.

The Analysis ToolPak Alternative

For statistical work, Excel includes a Data Analysis ToolPak (an add-in that ships with Excel and can be enabled from File > Options > Add-ins > Excel Add-ins, though the exact labels can vary slightly by version). Its Random Number Generation tool can produce a column of numbers drawn from a chosen distribution, including uniform, normal, Bernoulli, binomial, and Poisson, and unlike the worksheet functions it lets you specify a seed so a sequence can be reproduced. This makes it the better choice for repeatable simulations. The generated numbers are static values, so they do not recalculate.

Common Problems and Fixes

  • #NAME? error: usually means RANDARRAY is being used in a version of Excel older than Microsoft 365 or Excel 2021, or the function name is misspelled.
  • #SPILL! error: RANDARRAY needs empty cells below and beside it; a blocked range prevents the array from spilling.
  • Numbers changing constantly: that is expected behavior for volatile functions; paste as values to freeze them.
  • Calculation set to manual: if random numbers never change, check Formulas > Calculation Options and make sure it is set to Automatic.
  • Duplicates appearing: expected with plain RANDBETWEEN; switch to one of the unique-value methods above.

Frequently Asked Questions

What is the difference between RAND and RANDBETWEEN?

RAND() returns a decimal between 0 and 1 with many decimal places, while RANDBETWEEN(bottom, top) returns a whole number between two bounds you choose. RANDBETWEEN is essentially a convenient wrapper for scaling and rounding RAND's output.

How do I stop Excel random numbers from changing?

Copy the cells, then use Paste Special > Values to replace the formulas with their current results. Alternatively, set calculation to manual under Formulas > Calculation Options, though this affects all formulas on the sheet.

Can I get a random number between two decimals, like 1.5 and 7.5?

Yes. Use =RAND()*(7.5-1.5)+1.5, which scales the 0-to-1 output to your range, or in Microsoft 365 use =RANDARRAY(1,1,1.5,7.5) which accepts decimal bounds directly.

Is Excel's random number generator good enough for a prize drawing?

For casual draws and office raffles it is generally considered fair in practice, since the output is effectively unpredictable to users. Strictly speaking it is not a certified or cryptographic randomizer, so regulated lotteries use dedicated certified systems instead.

Can I generate random text or dates, not just numbers?

Yes, by combining functions. Random dates work well because Excel stores dates as numbers: =RANDBETWEEN(DATE(2024,1,1), DATE(2024,12,31)) returns a random day in that year, formatted as a date. Random text is usually done with =INDEX(list, RANDBETWEEN(1, COUNTA(list))), picking from a range of words you supply.

Does Excel have a SHUFFLE function?

There is no function literally named SHUFFLE, but in Microsoft 365 you can combine SORTBY with RANDARRAY, for example =SORTBY(A2:A20, RANDARRAY(COUNTA(A2:A20))), to randomize the order of a list in a single formula.