RANDOM_SEED(SIZE, PUT, GET, GENERATOR)

Purpose

Restarts or queries the pseudo-random number generator used by RANDOM_NUMBER.

Class

Subroutine

Argument type and attributes

There must either be exactly one or no arguments present.
SIZE (optional)
must be scalar and of type default integer. It is an INTENT(OUT) argument. It is set to the number of default type integers (N) that are needed to hold the value of the seed, which is an 8-byte variable.
PUT (optional)
must be a default integer array of rank one and size ≥ N. It is an INTENT(IN) argument. The seed for the current generator is transferred from it.
GET (optional)
must be a default integer array of rank one and size ≥ N. It is an INTENT(OUT) argument. The seed for the current generator is transferred to it.
IBM extension begins GENERATOR (optional)
must be a scalar and of type default integer. It is an INTENT(IN) argument. Its value determines the random number generator to be used subsequently. The value must be either 1 or 2. IBM extension ends

IBM extension begins Random_seed allows the user to toggle between two random number generators. Generator 1 is the default. Each generator maintains a private seed and normally resumes its cycle after the last number it generated. A valid seed must be a whole number between 1.0 and 2147483647.0 (2.0**31-1) for Generator 1 and between 1.0 and 281474976710656.0 (2.0**48) for Generator 2.

Generator 1 uses the multiplicative congruential method, with
S(I+1) = ( 16807.0 * S(I) ) mod (2.0**31-1)
and
X(I+1) = S(I+1) / (2.0**31-1)

Generator 1 cycles after 2**31-2 random numbers.

Generator 2 also uses the multiplicative congruential method, with
S(I+1) = ( 44,485,709,377,909.0 * S(I) )
              mod (2.0**48)
and
X(I+1) = S(I+1) / (2.0**48)

Generator 2 cycles after (2**48) random numbers. Although generator 1 is the default (for reasons of backwards compatibility) the use of generator 2 is recommended for new programs since it typically runs faster than generator 1 and has a longer period.

If no argument is present, the seed of the current generator is set to the default value 1d0. IBM extension ends

Examples

CALL RANDOM_SEED
   ! Current generator sets its seed to 1d0
CALL RANDOM_SEED (SIZE = K)
   ! Sets K = 64 / BIT_SIZE( 0 )
CALL RANDOM_SEED (PUT = SEED (1 : K))
   ! Transfer seed to current generator
CALL RANDOM_SEED (GET = OLD (1 : K))
   ! Transfer seed from current generator