ranf Function

public function ranf(seed)

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).

Arguments

Type IntentOptional Attributes Name
integer, intent(in), optional :: seed

Return Value real


Contents

Source Code


Source Code

  function ranf (seed)
# if RANDOM == _RANMT_
    use mt19937, only: sgrnd, grnd
# endif
    implicit none
    integer, intent(in), optional :: seed
    real :: ranf
    integer :: l
    integer, allocatable :: seed_in(:)
# 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