GRASS Programmer's Manual
6.4.3(2013)-r
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Macros
Pages
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
(
const
int
seed,
const
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
(seed);
24
y = -1 + 2 *
G_math_rand
(seed);
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
}
lib
gmath
gauss.c
Generated on Sat Oct 5 2013 12:11:07 for GRASS Programmer's Manual by
1.8.4