User Guide Getting Started Help Center Documentation Community Training
Looker
  
English
Français
Deutsch
日本語
rand

Back to Functions and Operators

The rand function can be used in custom filters and table calculations to return a random number between 0 and 1.

Syntax

rand()

The rand function returns a random number between 0 and 1.

Examples

The rand function is often used to generate random integers, sometimes to select a random sampling of data. For example, to generate an integer between 1 and 100 you could use:

round(rand()*100, 0)

This expression works as follows:

  1. Uses the rand() function to generate a random number between 0 and 1.
  2. Multiplies by 100 to turn it into a random number between 1 and 100.
  3. Uses the round function to round the random number to an integer.

You could then filter your report to only include data below a certain random number.

Another use case for the rand() function is to add jittering in scatterplots. Jittering enables you to add noise to a graph to avoid over plotting. For an example, see this Community topic.

Things to Know

The rand function produces a number with 16 decimal places, such as 0.04277424614631747.

Top