RND() Function - Random Number

Syntax

RND(int{,ERR=lineref})

For BBj-specific information, see the RND() Function - BBj.

Description

The RND() function returns a sequence of random numbers. The sequence of values returned is determined by a "seed value." The same sequence results each time a given seed is used.

Parameter

Description

int

Seed value. An integer in the range -32767 to +32767.

If int is greater than zero, RND() returns an integer in the range 0 to int-1. For example, RND(50) returns a random integer from 0 to 49.

If int is 0, a floating-point value of x is returned such that 0 <= x < 1. This is typical of most random number functions in other languages. Such a value can be multiplied and scaled to any desired range.

If int is negative, it sets the random-number seed to the ABS(int) and returns a result between 0 and 1, as described where int = 0.

ERR=lineref

Branch to be taken if an error occurs during execution.

Though PRO/5 cannot guarantee identical random number sequences between different implementations, the same seed is guaranteed to produce the same sequence ONLY on the same implementation. PRO/5 sets the RND() seed with the same value, whenever PRO/5 is loaded.

Examples

1000 LET A=RND(0); REM - VALUE BETWEEN 0 AND 1
1020 LET B=RND(-392); REM - SET SEED AND RETURN VALUE
1030 LET C=RND(52); REM - RETURN INT BETWEEN 0 AND 51

See Also

Functions - Alphabetical Listing