util.Math.rand
Returns a positive pseudo-random number.
Syntax
util.Math.rand(
max INTEGER )
RETURNS INTEGER
- max is the maximum random number that can be generated.
Usage
The rand()
function returns a pseudo-random integer number between
zero and max.
Important:
The srand()
function initializes the pseudo-random numbers generator. It must
be called before subsequent calls to the rand()
function. If you do not call the srand()
function,
the rand()
function will generate the same sequence of numbers for every program
execution. The numbers generated by rand()
can vary depending on the operating
system.
The maximum random number returned by the rand()
function is 2,147,483,646.
The rand()
function returns zero if the argument is lower or equal to 0.
Example
IMPORT util
MAIN
DEFINE i SMALLINT
DISPLAY "Before srand() call:"
FOR i=1 TO 3
DISPLAY util.Math.rand(100)
END FOR
CALL util.Math.srand()
DISPLAY "After srand() call:"
FOR i=1 TO 3
DISPLAY util.Math.rand(100)
END FOR
END MAIN
(run this example several times)