RAND and RANDBETWEEN Functions in Google Sheets

Published on

The RAND and RANDBETWEEN functions return a random number in Google Sheets. To return an array of random numbers, you can use the RANDARRAY function.

This tutorial discusses RAND and RANDBETWEEN and how they differ.

Before that, one important point: These functions will recalculate and return a new random number when you enter any data in the sheet, make other changes, reopen it, or according to the recalculation settings explained in this tutorial: Frequency of Recalculation for Volatile Functions in Google Sheets.

RAND Function in Google Sheets

Syntax:

RAND()

The RAND function doesn’t take any arguments. You simply enter it in any cell to get a random number.

Example:

=RAND()

The RAND function in Google Sheets returns a random number between 0 (inclusive) and 1 (exclusive), meaning it generates a random number between 0 and 0.9999999.

You may want a real-life use case for the RAND function in Google Sheets. Here is one:

Assume you want to pick one item randomly from the available two items. You can use the following formula:

=IF(RAND()>0.5, "Apple", "Orange")

You can replace “Apple” with “Heads” and “Orange” with “Tails” to use it for coin flipping. However, for this purpose, you can also use the RANDBETWEEN function or the currently undocumented COINFLIP function.

RANDBETWEEN Function in Google Sheets

Syntax:

RANDBETWEEN(low, high)

Arguments:

Unlike the RAND function, the RANDBETWEEN function takes two arguments.

  • low – The low end (the smallest integer) of the random range.
  • high – The high end (the largest integer) of the random range.

This formula returns a random integer between two values, both inclusive.

Example:

=RANDBETWEEN(6, 15)

This formula will return a random number between 6 and 15, both inclusive.

Here is one more example:

=TO_DATE(RANDBETWEEN("2024-06-01", "2024-06-30"))

This formula returns a random date between two dates. You can specify dates as the low and high ends of the function.

We use the TO_DATE function with RANDBETWEEN to convert the numeric value returned by the latter to a date.

Additional Tips

In RANDBETWEEN, if you specify 0 and 100 as the lowest and highest values, the random number can be any number from 0 to 100, both inclusive.

How do we make 0 inclusive, but 100 exclusive?

For this, we can use the following RAND and TRUNC combo, which returns a random number between 0 and 99:

=TRUNC(RAND()*100)
  • RAND() generates a random decimal number between 0 (inclusive) and 1 (exclusive).
  • Multiplying by 100 scales this to a range of 0 to just under 100.
  • TRUNC(...) removes the decimal part, leaving an integer between 0 and 99.

If you want a random number between 1 and 100, 1 inclusive, 100 exclusive, use this similar formula.

=TRUNC(RAND()*(100-1)+1)
  • RAND() generates a random decimal number between 0 (inclusive) and 1 (exclusive).
  • *(100-1) scales this random number to a range between 0 and 99.
  • +1 shifts the range to be between 1 and 100.
  • TRUNC(...) removes the decimal part, giving you an integer between 1 and 99.

Resources

Here are a few related resources in Google Sheets:

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Filter Top N per Category in Excel (Using FILTER & COUNTIFS)

You can use a combination of FILTER and COUNTIFS to filter the top N...

Rank per Group in Excel

You have two groups of 20 students each. How do you determine the rank...

Real-Time Excel Filtering Using Combo Box & FILTER Function

In this tutorial, you’ll learn how to set up real-time Excel filtering using a...

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

More like this

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

How to Extract Top N from Aggregated Query Results in Google Sheets

To summarize data in Google Sheets, you can use the QUERY function. However, if...

How to Use RANK IF in Google Sheets (Conditional Ranking)

You can use the RANK function to rank values in an entire dataset. But...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.