rng_uniform Function

public function rng_uniform(self) result(u)

Generate a uniformally-distributed random number in the range [0,1)

Arguments

TypeIntentOptionalAttributesName
type(rng_type), intent(inout) :: self

Random Number Generator

Return Value real(kind=Float64)

Uniform random deviate


Called by

proc~~rng_uniform~~CalledByGraph proc~rng_uniform rng_uniform proc~rng_normal rng_normal proc~rng_normal->proc~rng_uniform

Contents

Source Code


Source Code

function rng_uniform(self) result(u)
    !+ Generate a uniformally-distributed random number in the range [0,1)
    type(rng_type), intent(inout) :: self
        !+ Random Number Generator
    real(Float64)                 :: u
        !+ Uniform random deviate

    integer(Int32) :: ix,iy,k
    real(Float64) :: am 

    ix = self%state(1)
    iy = self%state(2)

    ix = ieor(ix,ishft(ix,13))
    ix = ieor(ix,ishft(ix,-17))
    ix = ieor(ix,ishft(ix,5))
    k=iy/IQ
    iy=IA*(iy - k*IQ) - IR*k
    if(iy.lt.0) iy = iy + IM
    self%state(1) = ix
    self%state(2) = iy

    am = nearest(1.0,-1.0)/IM
    u = am*ior(iand(IM,ieor(ix,iy)),1)

end function rng_uniform