Generate a uniformally-distributed random number in the range [0,1)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(rng_type), | intent(inout) | :: | self | Random Number Generator |
Uniform random deviate
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