Google Sheets RANDBETWEEN Function: A Complete Guide
In this article
The RANDBETWEEN function in Google Sheets generates a random whole number between two specific numbers that you define. To use it, enter =RANDBETWEEN(low, high) into a cell, where "low" is the smallest possible number and "high" is the largest. This is ideal for creating random sample sets, picking winners for a giveaway, or simulating data for a prototype spreadsheet.
What You'll Need
- A Google account with access to Google Sheets.
- A basic understanding of how to enter a formula into a cell.
- A defined range (a minimum and maximum value) for your random numbers.
Step-by-Step
- Open your Google Sheet: Launch your browser and navigate to your desired spreadsheet. Ensure you have selected the cell where you want the random number to appear.
- Initiate the formula: Type the equals sign (
=) into the cell. This tells Google Sheets that you are entering a function rather than plain text. - Type the function name: Enter
RANDBETWEENimmediately after the equals sign. As you type, Google Sheets may suggest the function in a dropdown menu; you can click it or continue typing. - Open the parenthesis: Type an opening parenthesis
(to begin defining the arguments for the function. - Enter the lower bound: Type the lowest whole number you want the function to possibly return. For example, if you want a number between 1 and 100, type
1. - Add a comma: Type a comma (
,) to separate the lower bound from the upper bound. - Enter the upper bound: Type the highest whole number you want the function to possibly return. Following the previous example, type
100. - Close the parenthesis and enter: Type the closing parenthesis
)and press the Enter key on your keyboard. The cell will now display a random integer within your specified range. - Fill the formula (Optional): If you need a list of random numbers, click the small blue square (the fill handle) at the bottom-right corner of the cell and drag it down or across the other cells you wish to populate.
Common Mistakes
One of the most frequent errors is swapping the order of the arguments. While Google Sheets is often flexible, placing the higher number before the lower number can lead to confusion or unexpected results in more complex nested formulas. Always follow the (low, high) sequence.
Another common mistake is attempting to use decimals. The RANDBETWEEN function is strictly for integers (whole numbers). If you enter a decimal, such as =RANDBETWEEN(1.5, 10.5), Google Sheets will truncate the decimals, treating them as 1 and 10. If you need random decimals, you must use the RAND function combined with some basic multiplication and addition.
Users also frequently forget that RANDBETWEEN is a volatile function. This means the number will change every single time the spreadsheet is edited, every time a cell is changed, or every time the page is refreshed. If you are using these numbers for a permanent record, such as assigning a permanent ID to a client, you cannot leave the formula active in the cell.
Lastly, some users try to reference cells that contain text instead of numbers. If your lower or upper bound refers to a cell that contains a word or a blank space, the function will return a #VALUE! error because it cannot perform a mathematical operation on non-numeric data.
Tips
Freezing the Random Numbers: Since the numbers change constantly, you can "freeze" them by converting the formula to a static value. Once the random numbers are generated, highlight the cells, copy them (Ctrl+C or Cmd+C), then right-click and select Paste special > Values only. This removes the formula and keeps the number that was generated at that moment.
Using Cell References: Instead of typing numbers directly into the formula, you can refer to other cells. For example, if cell A1 contains 1 and cell B1 contains 100, your formula would be =RANDBETWEEN(A1, B1). This allows you to change the range of your random numbers quickly by simply editing the values in A1 or B1 without having to rewrite the formula in every cell.
Generating Random Dates: Because Google Sheets stores dates as integers (the number of days since December 30, 1899), you can use RANDBETWEEN to pick a random date. To do this, enter the start date and end date into two cells, then use those cells as your low and high bounds. Format the result cell as a Date (Format > Number > Date) to see a calendar date instead of a five-digit number.
Creating a Random List of Names: You can combine RANDBETWEEN with the INDEX function to pick a random name from a list. If you have a list of names in cells A1 through A10, you can use =INDEX(A1:A10, RANDBETWEEN(1, 10)). This tells the sheet to look at the range A1:A10 and return the value found at a random row number between 1 and 10.
Troubleshooting
If the function is not working as expected, first check for the #VALUE! error. This almost always means one of your arguments is not a number. Check the cells you are referencing to ensure there are no hidden spaces or text characters. Ensure that your numbers are not formatted as text; you can check this by looking at the alignment—numbers usually align to the right of the cell by default, while text aligns to the left.
If you see a #NUM! error, it typically indicates that the formula is struggling with the range provided. Ensure that your lower bound is indeed lower than your upper bound. While the function often corrects this automatically, certain versions or complex sheets may trigger an error if the logic is inverted.
If the numbers are changing too often and it is disrupting your work, remember that any change to any cell in the entire workbook triggers a recalculation of all volatile functions. To stop this, you can change the calculation settings. Go to File > Settings > Calculation. Under the "Recalculation" dropdown, you can change it from "On change" to "On change and every minute" or "On change and every hour." However, the only way to stop it completely is to use the Paste Special > Values only method mentioned in the Tips section.
If the formula simply displays as text (e.g., you see "=RANDBETWEEN(1,10)" in the cell instead of a number), check to see if the cell is formatted as "Plain text." Go to Format > Number and select "Automatic." After changing the format, you may need to double-click the cell and press Enter to trigger the calculation.
Frequently Asked Questions
Can I use RANDBETWEEN to get a decimal number?
No, RANDBETWEEN only returns integers. To get a random decimal between two numbers, you can use the formula =RAND() * (high - low) + low.
How do I stop the numbers from changing every time I type?
You must copy the cells containing the formulas and then use Paste special > Values only to replace the formula with the resulting number.
Is there a limit to how large the numbers can be?
Google Sheets can handle very large integers, but for most practical purposes, you are limited by the maximum number size supported by the spreadsheet software, which is far larger than what is needed for most random sampling.
Can I use RANDBETWEEN to pick a random item from a dropdown list?
Not directly, but you can use it inside an INDEX function. Use =INDEX(range, RANDBETWEEN(1, COUNTA(range))) to pick a random item from a list of any length.
What is the difference between RAND and RANDBETWEEN?
RAND() generates a random decimal between 0 and 1. RANDBETWEEN(low, high) generates a random whole number between the two integers you specify.