# 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 initialized to a default state. The example below shows how to initialize the random seed based on the system’s time.

## Standard

Fortran 95 and later

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

subroutine init_random_seed()
integer :: i, n, clock
integer, dimension(:), allocatable :: seed

call random_seed(size = n)
allocate(seed(n))

call system_clock(count=clock)

seed = clock + 37 * (/ (i - 1, i = 1, n) /)
call random_seed(put = seed)

deallocate(seed)
end subroutine

random_number

category: intrinsics