Smart Systems for Home

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

Random Number in Excel: How to Use RAND and RANDBETWEEN

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To generate a random number in Excel, use the =RAND() function for a decimal between 0 and 1, or the =RANDBETWEEN(bottom, top) function for a whole number between two specific values. These functions are volatile, meaning they recalculate every time the worksheet is changed or refreshed, allowing you to create dynamic lists, sampling sets, or randomized identifiers quickly.

What You'll Need

  • A computer with Microsoft Excel installed (works on Office 365, Excel 2021, 2019, 2016, and earlier versions).
  • A basic understanding of how to click into a cell and type a formula.
  • A dataset if you are using random numbers to assign values to existing rows.

Step-by-Step

Method 1: Generating a Decimal Between 0 and 1

The RAND function is the simplest way to generate a random value. It requires no arguments inside the parentheses.

  1. Open your Excel workbook and select the cell where you want the random number to appear.
  2. Type =RAND() into the cell or the formula bar at the top.
  3. Press Enter. Excel will display a decimal number (e.g., 0.742391).
  4. To apply this to multiple cells, click the small green square (the fill handle) at the bottom-right corner of the cell and drag it down or across your desired range.

Method 2: Generating a Whole Number Between Two Values

When you need a specific range, such as a number between 1 and 100, RANDBETWEEN is the correct tool.

  1. Select the target cell.
  2. Type =RANDBETWEEN(.
  3. Enter the lowest possible number you want (the bottom), followed by a comma. For example, if you want a number starting from 1, type 1,.
  4. Enter the highest possible number you want (the top). For example, if the limit is 100, type 100.
  5. Close the parentheses and press Enter. The final formula should look like =RANDBETWEEN(1,100).
  6. Drag the fill handle to populate other cells with different random whole numbers.

Method 3: Generating a Random Decimal Within a Custom Range

If you need a decimal number between two specific values (e.g., between 5.5 and 10.5), you must combine RAND with a basic math formula.

  1. Select the target cell.
  2. Use the formula structure: =RAND() * (top - bottom) + bottom.
  3. For a range between 5.5 and 10.5, enter: =RAND() * (10.5 - 5.5) + 5.5.
  4. Press Enter. This tells Excel to take a random percentage and apply it to the difference between your two numbers, then add the starting offset.

Method 4: Using the Modern RANDARRAY Function

In newer versions of Excel (Office 365 and Excel 2021), the RANDARRAY function can fill an entire grid of cells at once without dragging the fill handle.

  1. Select a single cell where the top-left of your random grid will start.
  2. Type =RANDARRAY(rows, columns, min, max, integer).
  3. Example: To create a table 5 rows high and 3 columns wide, with whole numbers between 1 and 50, type: =RANDARRAY(5, 3, 1, 50, TRUE).
  4. Press Enter. Excel will automatically "spill" the numbers into the surrounding cells.

Common Mistakes

One of the most frequent errors is forgetting that random functions in Excel are volatile. This means every time you type in any other cell, delete a row, or press F9, every single random number in your sheet will change. If you are using these numbers for a lottery, a prize draw, or a scientific sample, you cannot leave them as formulas, or your results will shift constantly.

Another common mistake is entering non-numeric values into the RANDBETWEEN function. If you enter text or a cell reference that contains text, Excel will return a #VALUE! error. Ensure both the bottom and top arguments are integers.

Users also often confuse RAND and RANDBETWEEN. Remember: RAND is for percentages/decimals (0 to 1), while RANDBETWEEN is for whole integers (e.g., 1, 2, 3).

Tips

Freeze Your Numbers: To stop the numbers from changing, you must convert the formulas into static values. Select the cells containing the random numbers, press Ctrl + C to copy, then right-click the selection and choose Paste Values (the icon with "123"). This removes the formula and leaves only the resulting number.

Creating a Random List: If you have a list of names and want to randomize their order, create a new column next to the names. Use =RAND() in every cell of that column. Then, select your entire data range and use the Sort feature (Data tab > Sort) to sort the list based on the random number column. This effectively shuffles your original list.

Avoiding Duplicates: RANDBETWEEN does not guarantee unique numbers; it is possible to get the same number twice. If you need a unique set of random numbers, the best method is to list the numbers 1 through 100 in a column, use =RAND() in the next column, and sort the list by the random values.

Troubleshooting

If your formula is not working as expected, check these common points:

  • Formula showing as text: If you see =RAND() written in the cell instead of a number, the cell is likely formatted as "Text". Change the cell format to "General" via the Home tab, then click into the formula bar and press Enter again.
  • #NAME? Error: This usually happens if you misspelled the function name (e.g., =RANDBETWEN()) or if you are using RANDARRAY in an older version of Excel that does not support it.
  • #NUM! Error: In RANDBETWEEN, this occurs if the bottom number is larger than the top number. Ensure your first argument is the smaller value.
  • Numbers not updating: If you want the numbers to change but they aren't, check if "Manual Calculation" is turned on. Go to the Formulas tab > Calculation Options and ensure Automatic is selected.

Frequently Asked Questions

Can I generate random dates in Excel?

Yes. Excel stores dates as serial numbers. To get a random date between two dates, use =RANDBETWEEN(DATE(2023,1,1), DATE(2023,12,31)) and then format the cell as a "Date" using the Home tab.

How do I generate a random letter?

You can combine CHAR and RANDBETWEEN. To get a random uppercase letter (A-Z), use =CHAR(RANDBETWEEN(65, 90)). The numbers 65 and 90 represent the character codes for A and Z.

Is there a way to make the random numbers truly random?

Excel uses a pseudo-random number generator, which is sufficient for most business and educational needs. For high-level cryptographic security or professional gambling software, specialized software is required, as Excel's patterns can theoretically be predicted.

Why does my RANDARRAY formula say #SPILL!?

The #SPILL! error occurs when there is existing data in the cells where RANDARRAY is trying to place its results. Clear the cells below and to the right of your formula to give the function room to expand.

Can I use random numbers to pick a name from a list?

Yes. Use the INDEX function combined with RANDBETWEEN. For example, if your names are in cells A1 to A10, use =INDEX(A1:A10, RANDBETWEEN(1, 10)) to pick one name at random.