GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-bea8435a9e
gauss.c
Go to the documentation of this file.
1
#include <math.h>
2
#include <
grass/gmath.h
>
3
4
/*!
5
* \fn double G_math_rand_gauss(const int seed, const double sigma)
6
*
7
* \brief Gaussian random number generator
8
*
9
* Gaussian random number generator (mean = 0.0)
10
*
11
* \param[in] seed
12
& \param[in] sigma
13
* \return double
14
*/
15
16
double
G_math_rand_gauss
(
double
sigma)
17
{
18
double
x
, y, r2;
19
20
do
{
21
/* choose x,y in uniform square (-1,-1) to (+1,+1) */
22
x
= -1 + 2 *
G_math_rand
();
23
y = -1 + 2 *
G_math_rand
();
24
25
/* see if it is in the unit circle */
26
r2 =
x
*
x
+ y * y;
27
}
while
(r2 > 1.0 || r2 == 0);
28
29
/* Box-Muller transform */
30
return
sigma * y * sqrt(-2.0 * log(r2) / r2);
31
}
G_math_rand
float G_math_rand(void)
Definition:
rand1.c:16
G_math_rand_gauss
double G_math_rand_gauss(double sigma)
Definition:
gauss.c:16
gmath.h
x
#define x
lib
gmath
gauss.c
Generated on Sun Nov 24 2024 07:03:38 for GRASS GIS 8 Programmer's Manual by
1.9.1