The util.Math class / util.Math methods |
Returns a positive pseudo-random number.
util.Math.rand( max INTEGER ) RETURNING result INTEGER
The rand() function returns a pseudo-random integer number between zero and max.
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 according to 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.
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)