GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
double G_math_rand_gauss(const int seed, const double sigma)
Definition: gauss.c:17
int y
Definition: plot.c:34
log
Definition: wxnviz.py:54
float G_math_rand(int seed)
Random Number Generator (Uniform)
Definition: rand1.c:17