Fortran Wiki
random_seed

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.

Standard

Fortran 95 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

category: intrinsics