! Demo program to illustrate Fortran 90 Random_Seed and Random_Number.
! As posted by Athanasios Migdalas at comp.lang.fortran on 29 September
! 2002, with minor corrections.
Real :: harvest(10)
integer, allocatable :: newseed(:)
Integer :: dates(8), seed_size
character(LEN=10) :: date, time
CALL RANDOM_SEED () ! Initialize with system generated seed.
! To use Random_seed, first determine the random seed's
! array size since this may be different for each coompiler.
CALL RANDOM_SEED(SIZE=seed_size) ! Determine seed array size.
allocate(newseed(seed_size)) ! Allocate the seed array.
! Note: seed_size is 4 for G95, 1 for LF95, and 2 for Intel ifort.
! Generate a new seed as a "random" event of date information.
CALL DATE_AND_TIME(date,time,VALUES=dates)
newseed=dates(1)+dates(2)+dates(3)+dates(5)+dates(6)+dates(7)+dates(8)
write(*,*) 'Newseed=',newseed,' is of size=',seed_size
CALL RANDOM_SEED(Put=newseed) ! set Random_number with the new seed.
CALL RANDOM_NUMBER(harvest) ! create a random sequence.
write(*,*) 'U(0,1) Random Number=',harvest
call Random_Seed(Get=newseed) ! Get currenet seed.
write(*,*) 'Current random seed=', newseed
end