RAND()

 

Syntax:

       Then: a = RAND(n)

 

Returns a pseudo-random number between 0 and 32767.
Uses "n" as optional seed value.

 

Version Ref:  4.1

  5.0(Enhanced)

Description:

 

Returns a pseudo random number.

 

5.0 Enhanced to allow a negative seed value with current time to seed the generator.

 

Examples:

Then:  aa = mod(rand(xx), "100") + "1"

GETRAND if:  inkey ne "BRKY"

Then:  aa = mod(rand(" "), "100") + "1"; display; goto GETRAND

 

The above example returns a random number between 1 and 100. Notice that the seed value "rand(xx)" is only used ONCE and the second element, "GETRAND" loop, uses a NULL value for RAND e.g. rand(" "). RAND with a positive number should be seeded only once to work properly. For 2nd and subsequent iterations, use a NULL e.g. RAND(" ").

 

 Then: xx = RAND("-1")

 

The above seeds the generator with a negative value using current time.