GRASS GIS 8 Programmer's Manual
8.4.1(2025)-45ca3179ab
Loading...
Searching...
No Matches
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_gauss
double G_math_rand_gauss(double sigma)
Definition
gauss.c:16
G_math_rand
float G_math_rand(void)
Definition
rand1.c:16
x
#define x
gmath
gauss.c
Generated on Sat Jun 21 2025 21:07:27 for GRASS GIS 8 Programmer's Manual by
1.13.2