Revision [12794]

This is an old revision of KeyPgRandomize made by JeffMarshall on 2008-04-01 15:45:59.

 

RANDOMIZE


Seeds the random number generator

Syntax:
Usage:
Randomize [ seed ][, algorithm ]

Parameters:
seed
A KeyPgDouble double seed value for the random number generator. If omitted or set to -1.0, the KeyPgTimer Timer value will be used instead.
algorithm
An KeyPgInteger integer value to select the algorithm used. If omitted, the default algorithm for the current CompilerDialects language dialect is used.

Description:
Sets the random seed that helps KeyPgRnd Rnd generate random numbers, and selects the algorithm to use. Valid values for algorithm are:
0 - Default for current CompilerDialects language dialect. This is algorithm 3 in the CompilerOptlang -lang fb dialect, 4 in the CompilerOptlang -lang qb dialect and 1 in the CompilerOptlang -lang fblite dialect.
1 - Uses the C runtime library's rand() function. This will give different results depending on the platform.
2 - Uses a fast implementation. This should be stable across all platforms, and provides 32-bit granularity, reasonable degree of randomness.
3 - Uses the Mersenne Twister. This should be stable across all platforms, provides 32-bit granularity, and gives a high degree of randomness.
4 - Uses a QB compatible function. This should be stable across all platforms, and provides 24-bit precision, with a low degree of randomness.

For good results, using a seed that is not quite predictable should be used - for example, the value returned from KeyPgTimer Timer. This should not be done too frequently though, because for the non-QB algorithms the integer value is used, so the seed will only change once a second, and calling Randomize with the same seed will reset the sequence.

When you call Randomize in QB compatible mode, part of the old seed is retained. This means that if you call Randomize several times with the same seed, you will not get the same sequence each time. To get a specific sequence in QB compatible mode, set the seed by calling KeyPgRnd Rnd with a negative parameter.

Examples:
'' Seed the RNG, which is set to C's rand().
Randomize Timer, 1


Differences from QB:
See also:
Back to Mathematical Functions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode