9.226 RANDOM_SEED — Initialize a pseudo-random number sequence

Description:

Restarts or queries the state of the pseudorandom number generator used by RANDOM_NUMBER.

If RANDOM_SEED is called without arguments, it is seeded with random data retrieved from the operating system.

As an extension to the Fortran standard, the GFortran RANDOM_NUMBER supports multiple threads. Each thread in a multi-threaded program has its own seed. When RANDOM_SEED is called either without arguments or with the PUT argument, the given seed is copied into a master seed as well as the seed of the current thread. When a new thread uses RANDOM_NUMBER for the first time, the seed is copied from the master seed, and forwarded N * 2^{128} steps to guarantee that the random stream does not alias any other stream in the system, where N is the number of threads that have used RANDOM_NUMBER so far during the program execution.

Standard:

Fortran 90 and later

Class:

Subroutine

Syntax:

CALL RANDOM_SEED([SIZE, PUT, GET])

Arguments:
SIZE (Optional) Shall be a scalar and of type default INTEGER, with INTENT(OUT). It specifies the minimum size of the arrays used with the PUT and GET arguments.
PUT (Optional) Shall be an array of type default INTEGER and rank one. It is INTENT(IN) and the size of the array must be larger than or equal to the number returned by the SIZE argument.
GET (Optional) Shall be an array of type default INTEGER and rank one. It is INTENT(OUT) and the size of the array must be larger than or equal to the number returned by the SIZE argument.
Example:
program test_random_seed
  implicit none
  integer, allocatable :: seed(:)
  integer :: n

  call random_seed(size = n)
  allocate(seed(n))
  call random_seed(get=seed)
  write (*, *) seed
end program test_random_seed
See also:

RANDOM_NUMBER, RANDOM_INIT

Next: , Previous: , Up: Intrinsic Procedures [Contents][Index]

© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/RANDOM_005fSEED.html