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

RANDOM_INIT

Intrinsic Subroutine: Initializes the pseudorandom number generator used by RANDOM_NUMBER.

CALL RANDOM_INIT (repeatable, image_distinct)

repeatable

(Input) Must be scalar of type logical.

image_distinct

(Input) Must be scalar of type logical.

If repeatable has the value .true. and image_distinct has the value .true., the effect of a call to RANDOM_INIT is equivalent to calling RANDOM_SEED with a different processor-dependent value of PUT on each image that executes the call. If the invoking image index on the initial team is the same, the value of PUT is the same each time the program is executed.

If repeatable has the value .true. and image_distinct has the value .false., the effect of a call to RANDOM_INIT is equivalent to calling RANDOM_SEED with the same processor-dependent value of PUT on each image that executes the call. If the invoking image index on the initial team is the same, the value of PUT is the same each time the program is executed.

If repeatable has the value .false. and image_distinct has the value .true., the effect of a call to RANDOM_INIT is equivalent to calling RANDOM_SEED with a different processor-dependent value of PUT on each image that executes the call. If the invoking image index on the initial team is the same, the value of PUT is different each time the program is executed.

If repeatable has the value .false. and image_distinct has the value .false., the effect of a call to RANDOM_INIT is equivalent to calling RANDOM_SEED with the same processor-dependent value of PUT on each image that executes the call. If the invoking image index on the initial team is the same, the value of PUT is the different each time the program is executed.

NOTE:

This routine is thread safe.

Example

Consider the following:

PROGRAM main
REAL,DIMENSION(1000) :: y
CALL RANDOM_INIT (REPEATABLE=.TRUE., IMAGE_DISTINCT=.TRUE.)
CALL RANDOM_NUMBER (y)
. . .
END

After executing the above code, the array y contains a different sequence of pseudorandom numbers on each image that executes the code. If the program is executed multiple times, for an image that has the same image index in the initial team, the value of y is the same each time the program is run.

Consider another example:

PROGRAM main
REAL,DIMENSION(1000) :: y
CALL RANDOM_INIT (REPEATABLE=.FALSE., IMAGE_DISTINCT=.FALSE.)
CALL RANDOM_NUMBER (y)
. . .
END

After executing the above code, the array y contains the same sequence of pseudorandom numbers on each image that executes the code. If the program is executed multiple times, the value of y is different each time the program is run.