RND function

Purpose

Return a random number.

Syntax

y = RND

y = RND(a, b)

y = RND(numeric_expression)

Remarks

Floating point mode: RND returns a random value that is less than 1, but greater than or equal to 0.  Numbers generated by RND aren't really random, but are the result of applying a pseudo-random transformation algorithm to a starting ("seed") value.  Given the same seed, PowerBASIC's RND algorithm always produces the same sequence of "random" numbers.  The pseudo-random value is calculated internally as a single precision value, but returned as an extended precision representation so it can be readily used in any situation.

Integer Range mode: RND(a, b) returns a Long-integer in the range of a to b inclusive.  a and b can each be a numeric literal or a numeric expression that evaluates within the range of a Long-integer (-2,147,483,648 to 2,147,483,647).

Special effects mode: When used with a single numeric expression argument, the value returned by RND depends on the optional numeric value you supply as the argument, as follows:

With no argument, or with a positive argument, RND generates the next number in sequence based on the initial seed value.  With an argument of 0, RND repeats the last number generated.  A negative argument causes the random number generator to be re-seeded, so subsequent uses of RND with no argument or with a positive argument result in a new sequence of values.

Do not use 0 or negative value arguments in special effects mode unless you are looking for the special effects those argument values produce.

The random number generator can be reset back to the default seed using the following statement:

RANDOMIZE CVS(CHR$(255,255,255,255))

Note that each thread has its own, independent random number seed. See the discussion under RANDOMIZE for additional information on seeding the random number generator.

Example

See the example under RANDOMIZE.