random_norm Function

private function random_norm(mu, sigma)

This function returns a deviate of a Gaussian distribution

with mean , and standard deviation .

We use the Inverse Transform Sampling Method for sampling . With this method we get , where and are uniform random numbers in the interval .

Arguments

Type IntentOptional AttributesName
real(kind=rp), intent(in) :: mu

Mean value of the Gaussian distribution.

real(kind=rp), intent(in) :: sigma

Standard deviation of the Gaussian distribution.

Return Value real(kind=rp)

Sampled number from the Gaussian distribution .


Called by

proc~~random_norm~~CalledByGraph proc~random_norm random_norm proc~thermal_distribution thermal_distribution proc~thermal_distribution->proc~random_norm

Contents

Source Code


Source Code

  FUNCTION random_norm(mu,sigma)
    !! @note Gaussian random number generator. @endnote
    !! This function returns a deviate of a Gaussian distribution
    !! $$f_G(x;\mu,\sigma) = 
    !! \frac{1}{\sigma\sqrt{2\pi}} \exp{\left( -(x-\mu)^2/2\sigma^2 \right)},$$
    !!
    !! with mean \(\mu\), and standard deviation \(\sigma\).
    !!
    !! We use the Inverse Transform Sampling Method for sampling \(x\). 
    !! With this method we get \(x = \sqrt{-2\log{(1-y)}}\cos(2\pi z)\),
    !! where \(y\) and \(z\) are uniform random numbers in the interval \([0,1]\).
    REAL(rp), INTENT(IN) 	:: mu
    !! Mean value \(\mu\) of the Gaussian distribution.
    REAL(rp), INTENT(IN) 	:: sigma
    !! Standard deviation \(\sigma\) of the Gaussian distribution.
    REAL(rp) 				:: random_norm
    !! Sampled number \(x\) from the Gaussian distribution \(f_G(x;\mu,\sigma)\).
    REAL(rp) 				:: rand1
    !! Uniform random number in the interval \([0,1]\).
    REAL(rp) 				:: rand2
    !! Uniform random number in the interval \([0,1]\).

    call RANDOM_NUMBER(rand1)
    call RANDOM_NUMBER(rand2)

    random_norm = SQRT(-2.0_rp*LOG(1.0_rp-rand1))*COS(2.0_rp*C_PI*rand2);
  END FUNCTION random_norm