GRASS GIS 7 Programmer's Manual
7.0.5(2016)-r00000
gauss.c
Go to the documentation of this file.
1
#include <math.h>
2
#include <grass/gmath.h>
3
4
17
double
G_math_rand_gauss
(
double
sigma)
18
{
19
double
x, y, r2;
20
21
do
{
22
/* choose x,y in uniform square (-1,-1) to (+1,+1) */
23
x = -1 + 2 *
G_math_rand
();
24
y = -1 + 2 *
G_math_rand
();
25
26
/* see if it is in the unit circle */
27
r2 = x * x + y * y;
28
}
29
while
(r2 > 1.0 || r2 == 0);
30
31
/* Box-Muller transform */
32
return
sigma * y * sqrt(-2.0 * log(r2) / r2);
33
}
G_math_rand_gauss
double G_math_rand_gauss(double sigma)
Definition:
gauss.c:17
G_math_rand
float G_math_rand(void)
Definition:
rand1.c:17
gmath
gauss.c
Generated on Sun Oct 2 2016 20:26:53 for GRASS GIS 7 Programmer's Manual by
1.8.12