221 of 286
207 Rnd Type Function returning Single Invocation Rnd() Discussion This function will return a pseudo-random value in the range of 0.0 to 1.0. The first time that Rnd() is called after the processor starts up the pseudo-random number generator is initialized with a seed value. The sequence of values returned will be repeatable when starting from the same seed. You can alter the sequence of returned values in two ways. Firstly, you can set the value of Register.SeedPRNG. The next call to Rnd() will initialize the pseudo-random number generator with that seed value before returning the first random value. The second way to modify the sequence is to call the Randomize() subroutine. Doing so will initialize the pseudo-random number generator with the current value of Register.RTCTick. This provides a way to introduce some non-repeatability into the sequence of values returned by Rnd(). It is especially effective if the time at which Randomize() is called is controlled by some external, unpredictable event like a user pressing a key. Example Dim i as Integer ' print 10 random values For i = 1 to 10 Debug.Print CStr(Rnd()) Next Compatibility BasicX does not support Register.seedPRNG. Instead, it has a system global variable named seedPRNG. This built-in variable is also supported in ZBasic for compatibility. See Also Randomize