program ran_test

use ifport

integer, dimension(:), allocatable :: seed1, seed2
integer seed_size

! Get size of seed
call random_seed (SIZE=seed_size)
allocate (seed1(seed_size), seed2(seed_siZe))

! Get initial seed
call random_seed (GET=seed1)
print *, seed1

! Call random_seed with no arguments and see if it changes
call random_seed
call random_seed (GET=seed2)
print *, seed2

if (ALL(seed1 == seed2)) then
  write (*,*) "FAIL - Calling RANDOM_SEED with no arguments does not change seed"
else
  ! Make sure that seed is time-based
  write (*,*) "Waiting 5 seconds..."
  call sleepqq(5000)
  call random_seed
  call random_seed (GET=seed1)
  print *, seed1
  if (ALL(seed1==seed2)) then
    write (*,*) "FAIL - Calling RANDOM_SEED with no arguments does not set time-based seed"
  else
    write (*,*) "PASS - Calling RANDOM_SEED with no arguments sets time-based seed"
  end if
end if

! Does a PUT change the seed?
call random_seed(GET=seed1)
print *, seed1
seed2 = seed1*2
print *, seed2
call random_seed(PUT=seed2)
call random_seed(GET=seed1)
print *, seed1
if (ALL(seed1==seed2)) then
  write (*,*) "PASS - RANDOM_SEED(PUT=) works"
else
  write (*,*) "FAIL - RANDOM_SEED(PUT=) is ignored"
end if

end program ran_test