4. Elements of OpenSQL Statements : Functions : Scalar Functions : Random Number Functions
 
Share this page                  
Random Number Functions
The random number function is used to generate random values. Use the following statement to set the beginning value for the random functions:
[exec sql] set random_seed [value]
There is a global seed value and local seed values. The global value is used until you issue “set random_seed,” which changes the value of the local seed. Once changed, the local seed is used for the whole session. If you are using the global seed value, the seed is changed whenever a random function executes. This means that other users issuing random calls will enhance the “randomness” of the returned value. Note that the seed value can be any integer.
If you omit the value, then Ingres multiplies the process ID by the number of seconds past 1/1/2016 until now. This value generates a random starting point. You can use value to run a regression test from a static start and get identical results.
There are four random number functions:
random() - Returns a random integer based on a seed value.
randomf() - Returns a random float based on a seed value between 0 and 1. This is slower than random, but produces a more random number.
random(l,h) - Returns a random integer in the specified range
(that is, l >= x <= h).
randomf(l,h) - Passing two integer values generates an integer result in the specified range; passing two floats generates a float in the specified range; passing an int and a float causes them to be coerced to an int and generates an integer result in the specified range (that is, l >= x <= h).