Syed Arefinul Haque
Syed Arefinul Haque

Reputation: 1325

Is there a way to seed the random number generation process in BigQuery Standard SQL

I have used the LegacySQL rand() function (found here) before which takes an integer as an argument for seeding the random number generation process.

When I started using the same rand() function in StandardSQL (found here), it does not allow me to provide a seed. So my question is if I want do some seeding when generating number, is there a way to do it in StandardSQL in BigQuery?

This is important because in scientific research sometimes we need to deal with random numbers but also the results need to be reproducible.

Upvotes: 4

Views: 8143

Answers (2)

Thaddeus Watts
Thaddeus Watts

Reputation: 41

As the above answer states, No, but you may be able to do something similar with a hash function such as sha256, sha1 or md5.

I use this to sort my output into a random order that is the same every time.

Upvotes: 4

juferafo
juferafo

Reputation: 556

Unfortunately, there is no way to provide a seed into the RAND() function in the standard SQL language. In this public issue tracker you can see that the integer types created a problematic scenario in the RAND() function. These issues were corrected in standard SQL and, as a consequence, some built-in functions were modified.

Upvotes: 4

Related Questions