Visible to Intel only — GUID: GUID-2953E97A-AAE2-4064-977D-35AA7132441D
Visible to Intel only — GUID: GUID-2953E97A-AAE2-4064-977D-35AA7132441D
RANDOM_SEED
Intrinsic Subroutine (Generic): Changes or queries the seed (starting point) for the pseudorandom number generator used by intrinsic subroutine 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.
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).
If RANDOM_SEED is called with no arguments, the seed is set to a different, unpredictable value on each call.
This routine is thread safe.
Example
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 the 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