Skip to main content
Previous section   Next section

RANDOMIZE

Initializes the random-number generator.

Synopsis

RANDOMIZE [number]

Arguments

number Optional — Any valid numeric expression.

Description

The RANDOMIZE statement uses number to initialize the RND function's random-number generator, giving it a seed value. By specifying the same RANDOMIZE number seed, you can use RND to repeatedly generate the same “random” number.

To restore true randomness, issue a RANDOMIZE statement without the number argument. If you omit number, the value returned by the system internal clock is used as the new seed value.

If RANDOMIZE is not used, the RND function uses the system internal clock as a seed the first time it is called, and thereafter uses the last generated random number as the next seed value.

Examples

The following example illustrates use of the RANDOMIZE statement:

RANDOMIZE 10;  ! Seeds random-number generator
PRINT RND(7)
  ! Generates a random value between 1 and 6
PRINT RND(7)
  ! Generates the same "random" value as above
RANDOMIZE;     ! Restores randomness
PRINT RND(7)
  ! Generates a random value between 1 and 6
Copy code to clipboard

See Also