Randomize

Description

Initializes the random number generator so that the Rand function begins a new series of pseudorandom numbers.

Syntax

Randomize ( n )

Argument

Description

n

The starting value (seed) for the random number generator. When n is 0, PowerBuilder takes the seed from the system clock and begins a nonrepeatable sequence. A nonzero number generates a different but repeatable sequence for each seed value. n cannot exceed 32,767.

Returns

Integer. If n is null, Randomize returns null. The return value is never used.

Usage

The sequence of numbers generated by repeated calls to the Rand function is a computer-generated pseudorandom sequence. You can use the Randomize function to initialize the random number generator with a value from the system clock, or some other changing value, so that the sequence is always different. For testing purposes, you can select a specific seed value, which you can reuse to make the pseudorandom sequence repeatable each time you run the application.

Include Randomize in the script for the Open event in the application.

Examples

Example 1

This statement sets the seed for the random number generator to 0 so that calls to Rand generate a new sequence each time the script is run:

Randomize(0)

Example 2

This statement sets the seed for the random number generator to 4 so that calls to Rand repeat a specific sequence each time the random number generator is initialized:

Randomize(4)

See also