Generate a normally-distributed random number with mean 0 and standard deviation 1
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(rng_type), | intent(inout) | :: | self | Random Number Generator |
Normal random deviate
function rng_normal(self) result(n)
!+ Generate a normally-distributed random number with mean 0 and standard deviation 1
type(rng_type), intent(inout) :: self
!+ Random Number Generator
real(Float64) :: n
!+ Normal random deviate
real(Float64), parameter :: s = 0.449871d0
real(Float64), parameter :: t = 0.386595d0
real(Float64), parameter :: a = 0.196000d0
real(Float64), parameter :: b = 0.254720d0
real(Float64), parameter :: r1 = 0.27597d0
real(Float64), parameter :: r2 = 0.27846d0
real(Float64) :: u, v, x, y, q
do
u = rng_uniform(self)
v = rng_uniform(self)
v = 1.7156d0 * (v - 0.5d0)
x = u - s
y = abs(v) + t
q = x**2 + y*(a*y - b*x)
if (q.lt.r1) exit
if (q.gt.r2) cycle
if((v**2).lt.(-4.0*log(u)*u**2)) exit
enddo
n = v/u
end function rng_normal