Intrinsic Subroutine (Generic): Changes or queries the seed (starting point) for the pseudorandom number generator used by RANDOM_NUMBER. Intrinsic subroutines cannot be passed as actual arguments.
CALL RANDOM_SEED ([size] [,put] [,get])
size |
(Output; optional) Must be scalar and of type integer. Set to the number of integers (N) that the processor uses to hold the value of the seed. |
put |
(Input; optional) Must be an integer array of rank one and size greater than or equal to N. It is used to reset the value of the seed. |
get |
(Output; optional) Must be an integer array of rank one and size greater than or equal to N. It is set to the current value of the seed. |
No more than one argument can be specified. If no argument is specified, a random number based on the date and time is assigned to the seed.
At run-time, the arguments are examined in the order size then put then get. The first optional argument in this order that is present determines the behavior of the RANDOM_SEED call.
You can determine the size of the array the processor uses to store the seed by calling RANDOM_SEED with the size argument (see the second example below).
Consider the following:
CALL RANDOM_SEED ! Processor initializes the
! seed randomly from the date
! and time
CALL RANDOM_SEED (SIZE = M) ! Sets M to N
CALL RANDOM_SEED (PUT = SEED (1 : M)) ! Sets user seed
CALL RANDOM_SEED (GET = OLD (1 : M)) ! Reads current seed
The following shows another example:
INTEGER I
INTEGER, ALLOCATABLE :: new (:), old(:)
CALL RANDOM_SEED ( ) ! Processor reinitializes the seed
! randomly from the date and time
CALL RANDOM_SEED (SIZE = I) ! I is set to the size of
! the seed array
ALLOCATE (new(I))
ALLOCATE (old(I))
CALL RANDOM_SEED (GET=old(1:I)) ! Gets the current seed
WRITE(*,*) old
new = 5
CALL RANDOM_SEED (PUT=new(1:I)) ! Sets seed from array
! new
END