generate random numbers, and selects the algorithm to use. Valid values for
0 - Default for current
language dialect. This is algorithm
3 in the
-lang fb dialect,
4 in the
-lang qb dialect and
1 in the
-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 function that is designed to give the same random number sequences as QBASIC. This should be stable across all platforms, and provides 24-bit precision, with a low degree of randomness.
5 - Available on Win32 and Linux, using system features (Win32 Crypto API, Linux /dev/urandom) to provide cryptographically random numbers. If those system APIs are unavailable, algorithm
3 will be used instead.
For any given seed, each algorithm will produce a specific, deterministic sequence of numbers for that seed. If you want each call to
Randomize to produce a different sequence of numbers, a seed that is not quite predictable should be used - for example, the value returned from
Timer. Omitting the
seed parameter will use a value based on this.
Note: using the
Timer value directly as a parameter will produce the same seed if used more than once in the same second. However, it is generally not worth calling
Randomize twice with unpredictable seeds anyway, because the second sequence will be no more random than the first. In most cases, the Mersenne twister should provide a sufficiently random sequence of numbers, without requiring reseeding between
Rnd calls.
When you call
Randomize with the QB compatible algorithm, 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
Rnd with a negative parameter.