Returns a pseudorandom number range in [0., 1.), (i.e. 0<= ranf < 1). The generator is initialized with the given seed if passed, otherwise uses the seed already set (default or otherwise).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | optional | :: | seed |
real function ranf (seed)
# if RANDOM == _RANMT_
use mt19937, only: sgrnd, grnd
# endif
implicit none
integer, intent(in), optional :: seed
# if RANDOM != _RANMT_
integer :: l
integer, allocatable :: seed_in(:)
# endif
# if RANDOM == _RANMT_
if (present(seed)) call sgrnd(seed)
ranf = grnd()
# else
if (present(seed)) then
call random_seed(size=l)
allocate(seed_in(l))
! @note This is probably not ideal, instead we could use
! [[set_seed_from_single_integer]] instead
seed_in(:)=seed
call random_seed(put=seed_in)
endif
call random_number(ranf)
# endif
end function ranf