Random Number Between 2 Integers

Rand Between in BigQuery

Description

Generating random numbers is a good way to test out our code or to randomize results.
In BigQuery there is a RAND function which will generate a number between 0 and 1.
But sometimes it’s helpful to get a random integer within a specified range. This snippet will do that:

SELECT 
   ROUND(<min> + RAND() * (<max> - <min>)) rand_between
FROM 
   <TABLE>

where:

  • <min>, <max> is the range between which you want to generate a random number

Example:

Random Numbers

I use this one so often! Thank you :smiley: