RANDOM_SEED

Intrinsic Subroutine: Changes or queries the seed (starting point) for the pseudorandom number generator used by RANDOM_NUMBER.

Syntax

CALL RANDOM_SEED ([size] [, put] [, get])

size
(Optional; output) Must be scalar and of type default integer. Number of integers the processor uses to hold the value of the seed.

put
(Optional; input) Must be a default integer array of rank one. It is used by the processor to reset the value of the seed.

get
(Optional; output) Must be a default integer array of rank one. It is set to the current value of the seed.

No more than one argument can be specified. Both put and get must be greater than or equal to the size of the array the processor uses to store the seed. You can determine this size by calling RANDOM_SEED with the size argument (see second example).

If no argument is specified, a random number based on the date and time is assigned to the seed.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: RANDOM_NUMBER, SEED, SRAND

Examples

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