Lahey/GNU Fortran

Next: , Previous: RANDOM_NUMBER, Up: Intrinsic Procedures


8.200 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 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
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:
          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
     

See also:
RANDOM_NUMBER