简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM