random_norm Function

private function random_norm(mean, sigma)

@brief Gaussian random number generator. @details This function returns a deviate of a Gaussian distribution @f$f_G(x;\mu,\sigma) = \frac{1}{\sigma\sqrt{2\pi}} \exp{\left( -(x-\mu)^2/2\sigma^2 \right)}@f$, with mean @f$\mu@f$, and standard deviation @f$\sigma@f$.

We use the Inverse Transform Sampling Method for sampling @f$x@f$. With this method we get @f$x = \sqrt{-2\log{(1-y)}}\cos(2\pi z)@f$, where @f$y@f$ and @f$z@f$ are uniform random numbers in the interval @f$[0,1]@f$.

@param[in] mu Mean value @f$\mu@f$ of the Gaussian distribution. @param[in] mu Standard deviation @f$\sigma@f$ of the Gaussian distribution. @param random_norm Sampled number @f$x@f$ from the Gaussian distribution @f$f_G(x;\mu,\sigma)@f$. @param rand1 Uniform random number in the interval @f$[0,1]@f$. @param rand2 Uniform random number in the interval @f$[0,1]@f$.

Arguments

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

Return Value real(kind=rp)


Contents

Source Code


Source Code

FUNCTION random_norm(mean,sigma)
	REAL(rp), INTENT(IN) 	:: mean
	REAL(rp), INTENT(IN) 	:: sigma
	REAL(rp) 				:: random_norm
	REAL(rp) 				:: rand1
	REAL(rp) 				:: rand2

	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