Next: RAND, Previous: RANDOM_NUMBER, Up: Intrinsic Procedures
RANDOM_SEED
— Initialize a pseudo-random number sequenceRANDOM_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.
CALL RANDOM_SEED(SIZE, PUT, GET)
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.
|
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