Formula to Generate Random Numbers in Excel

Formulas & functions · Updated November 23, 2026

The core formula to generate random numbers in Excel is =RAND() for a decimal between 0 and 1, or =RANDBETWEEN(bottom, top) for a whole number within a range you specify. For example, =RANDBETWEEN(1, 100) returns an integer from 1 to 100, and =RAND()*100 returns a decimal between 0 and 100. These functions recalculate every time the worksheet changes, which is both their power and their main limitation.

How RAND and RANDBETWEEN Work

Excel’s random functions use a pseudo-random number generator, meaning they follow a deterministic algorithm that produces a sequence of numbers that appear random. The starting point, called a seed, is derived from the system clock, so each recalculation gives a new sequence. RAND() returns a value greater than or equal to 0 and less than 1, with about 15 digits of precision. RANDBETWEEN(bottom, top) returns an integer inclusive of both endpoints, so =RANDBETWEEN(1, 6) simulates a fair die roll.

Both functions are volatile, meaning they recalculate whenever Excel performs any calculation—for example, when you edit a cell, open the workbook, or press F9 (Windows) or Cmd+= (Mac). This is useful for live simulations, but it also means the numbers change constantly, which is often not what you want for a static list.

How to Generate a Fixed List of Random Numbers

To keep the random numbers from changing, you need to convert the formulas to static values. The simplest method:

  1. Enter =RAND() or =RANDBETWEEN(1, 100) in the first cell.
  2. Drag the fill handle down or across to fill the range.
  3. Select the entire range of formulas.
  4. Press Ctrl+C (Windows) or Cmd+C (Mac) to copy.
  5. Right-click the selection, choose Paste Special, then select “Values” and click OK.

Alternatively, you can use the Ribbon: Home > Paste > Paste Values. This replaces the formulas with the last calculated numbers, freezing them permanently.

Using RANDARRAY for a Dynamic Array of Random Numbers

If you have Excel 365 or Excel 2021, RANDARRAY is a more powerful option. It returns an array of random numbers in one step, and it can fill multiple rows and columns. The syntax is:

=RANDARRAY(rows, [columns], [min], [max], [integer])

  • rows – number of rows to fill (required).
  • columns – number of columns (optional, defaults to 1).
  • min – smallest value (optional, defaults to 0).
  • max – largest value (optional, defaults to 1).
  • integer – TRUE for whole numbers, FALSE or omitted for decimals.

Example: =RANDARRAY(10, 1, 1, 100, TRUE) creates a vertical list of 10 random integers between 1 and 100. Because it’s a dynamic array, the entire spill range recalculates together, and you can still copy and paste as values to freeze them.

How to Generate Random Numbers Without Duplicates

Neither RAND nor RANDBETWEEN guarantees uniqueness. To generate a set of unique random numbers, use a helper column with RAND() and then sort, or use the SORTBY function with a random array. A common approach:

  1. In column A, list the numbers you want to randomize (e.g., 1 to 100 in A1:A100).
  2. In column B, enter =RAND() in each row.
  3. Select both columns and sort by column B (Data > Sort).

For a formula-based solution in Excel 365, use =SORTBY(SEQUENCE(10), RANDARRAY(10)) to get 10 random numbers from 1 to 10 in a random order, which is effectively a permutation without replacement.

Choosing Between RAND, RANDBETWEEN, and RANDARRAY

Your choice depends on your needs:

  • RAND() – best for continuous decimal values, e.g., probabilities or scaling.
  • RANDBETWEEN() – best for simple integer ranges, like dice or lottery numbers.
  • RANDARRAY() – best when you need a large block of random numbers quickly, especially with dynamic arrays.

For most everyday tasks, RANDBETWEEN is the most intuitive because you specify the range directly. However, if you need random decimals with a custom minimum and maximum, RAND()*(max-min)+min is a classic formula. For example, =RAND()*(50-10)+10 gives a decimal between 10 and 50.

Common Problems and How to Fix Them

One frequent issue is that random numbers keep changing when you don’t want them to. As noted, paste as values to fix them. Another problem is that RANDBETWEEN returns the same number repeatedly if you copy it down without recalculation—but that’s rare. If you need a random sample from a list, combine INDEX with RANDBETWEEN: =INDEX(A2:A100, RANDBETWEEN(1, COUNTA(A2:A100))) picks a random item from a list.

If you get a #NAME? error, it’s likely because you’re using RANDARRAY in an older version of Excel. In that case, use the older functions or upgrade to Microsoft 365. Also, remember that RAND() and RANDBETWEEN() are volatile, so if you have a large workbook, they can slow down recalculation. To minimize impact, limit their use or replace with static values after generation.

Alternatives: Using Excel’s Analysis ToolPak or VBA

For more control, you can use VBA to generate random numbers. A simple macro:

Sub GenerateRandomNumbers()
    Dim i As Integer
    For i = 1 To 10
        Cells(i, 1).Value = WorksheetFunction.RandBetween(1, 100)
    Next i
End Sub

This fills A1:A10 with random integers. Remember to save a copy of your workbook before running any macro, as macros cannot be undone with Ctrl+Z. The Analysis ToolPak add-in also offers a “Random Number Generation” tool under Data > Data Analysis, which provides more distribution options (normal, binomial, etc.), but it’s less commonly used than the built-in functions.

Frequently Asked Questions

How do I make random numbers not change?

Copy the cells containing the formulas, then use Paste Special > Values. This replaces the formulas with static numbers, so they won’t recalculate.

Can I generate random numbers between 0 and 1?

Yes, =RAND() does exactly that. To get a number between 0 and 1 with more control, use =RAND() directly.

What is the difference between RAND and RANDBETWEEN?

RAND returns a decimal between 0 and 1. RANDBETWEEN returns an integer within a range you specify. Both are volatile and recalculate with every change.

How do I generate a random date in Excel?

Dates are stored as numbers, so use =RANDBETWEEN(DATE(2020,1,1), DATE(2025,12,31)) and format the cell as a date. This returns a random date between the two dates.

Does RANDARRAY work in Excel 2019?

No, RANDARRAY requires Excel 365 or Excel 2021. In older versions, use RAND or RANDBETWEEN and fill down.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.