Seed the choosen random number generator.
If randomize=T, a random seed based on date and time is used.
(this randomizing procedure is proposed in GNU gfortran manual.)
Otherwise, it sets the seed using init_seed
In either case, it sets init_seed
to the initial seed used on return.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | randomize | |||
integer, | intent(inout), | dimension(:) | :: | init_seed |
subroutine init_ranf(randomize, init_seed)
use constants, only: kind_id
# if RANDOM == _RANMT_
use mt19937, only: sgrnd
# endif
implicit none
logical, intent(in) :: randomize
integer, intent(in out), dimension(:) :: init_seed
integer :: i, nseed, dt(8)
integer (kind=kind_id) :: t
if (randomize) then
call system_clock(t)
if (t == 0) then
call date_and_time(values=dt)
t = (dt(1) - 1970) * 365_kind_id * 24 * 60 * 60 * 1000 &
+ dt(2) * 31_kind_id * 24 * 60 * 60 * 1000 &
+ dt(3) * 24_kind_id * 60 * 60 * 1000 &
+ dt(5) * 60 * 60 * 1000 &
+ dt(6) * 60 * 1000 + dt(7) * 1000 &
+ dt(8)
end if
else
t = 0
end if
# if RANDOM == _RANMT_
if (randomize) then
init_seed(1) = lcg(t)
endif
call sgrnd(init_seed(1))
# else
if (randomize) then
! We should probably check that size(init_seed) >= nseed
call random_seed(size=nseed)
do i = 1, nseed
init_seed(i) = lcg(t)
end do
endif
call random_seed(put=init_seed)
# endif
end subroutine init_ranf