Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

RANDU

Intrinsic Subroutine (Generic): Computes a pseudorandom number as a single-precision value. Intrinsic subroutines cannot be passed as actual arguments.

CALL RANDU (i1,i2,x)

i1, i2

(Input; output) Must be scalars of type INTEGER(2) or INTEGER(4). They contain the seed for computing the random number. These values are updated during the computation so that they contain the updated seed.

x

(Output) Must be a scalar of type REAL(4). This is where the computed random number is returned.

The result is returned in x, which must be of type REAL(4). The result value is a pseudorandom number in the range 0.0 to 1.0. The algorithm for computing the random number value is based on the values for i1 and i2.

The result value is a pseudorandom number in the range 0.0 to 1.0. The algorithm for computing the random number value is based on the values for i1 and i2.

If i1 = 0 and i2 = 0, the generator base is set as follows:

    x(n + 1) = 2**16 + 3 

Otherwise, it is set as follows:

    x(n + 1) = (2**16 + 3) * x(n) mod 2**32 

The generator base x(n + 1) is stored in i1, i2. The result is x(n + 1) scaled to a real value y(n + 1), for 0.0 <= y(n + 1) < 1.

Example

Consider the following:

REAL X
INTEGER(2) I, J
...
CALL RANDU (I, J, X)

If I and J are values 4 and 6, X has the value 5.4932479E-04.