RANDOM Function

The RANDOM function accepts a call-by-name integer and returns a pseudorandom real number that is greater than or equal to 0 and less than 1. The number is generated by the mixed congruent method, which is designed to give a uniform distribution.

RANDOM is the only function described in this section that takes a call-by-name input parameter. The parameter gives an initial value that is thereafter changed to give succeeding values by the procedure itself.

You can obtain starting values to acquire a good sequence of pseudorandom numbers by picking odd integers close in value to 2**19, 2**40, or 2**41.

The procedure for RANDOM generates integers in the range 0 through 2**(39-1) and then returns those integers divided by 2**39. The integer variable N given to RANDOM is changed as follows:

The operator := is the replacement operator. A is a constant whose value depends on the sign of N (which is never changed), as follows:

  • For nonnegative N: A = 152587890725

  • For negative N: A = 277626315293

These values permit two different pseudorandom sequences depending on whether the starting value was positive or negative.

The random number is computed as follows:

RANDOM(N) = ABS(N)/(2**39)