Expand/Shrink

set_rand

Definition: set_rand(atom seed)
Description: Set the random number generator seed, to get a repeatable series of random numbers on subsequent calls to rand()/rnd().
Comments: Normally the numbers returned by the rand() function are totally unpredictable, and will be different each time you run your program. Sometimes however you may wish to be given the same series of numbers, for instance when debugging a program.

Note that if more that one thread invokes the rand() function, the results are likely to be unpredictable whether or not the set_rand() function has been called.
Example:
sequence s, t
s = repeat(0, 3)
t = s
set_rand(12345)
s[1] = rand(10)
s[2] = rand(100)
s[3] = rand(1000)
set_rand(12345)  -- same value for set_rand()
t[1] = rand(10)  -- same arguments to rand() as before
t[2] = rand(100)
t[3] = rand(1000)
-- at this point s and t will be identical
Implementation: See :%opSetRand in builtins\VM\pRand.e (an autoinclude) for details of the actual implementation.
See Also: rand, get_rand