GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
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 */
16{
17 double x, y, r2;
18
19 do {
20 /* choose x,y in uniform square (-1,-1) to (+1,+1) */
21 x = -1 + 2 * G_math_rand();
22 y = -1 + 2 * G_math_rand();
23
24 /* see if it is in the unit circle */
25 r2 = x * x + y * y;
26 } while (r2 > 1.0 || r2 == 0);
27
28 /* Box-Muller transform */
29 return sigma * y * sqrt(-2.0 * log(r2) / r2);
30}
float G_math_rand(void)
Definition rand1.c:15
double G_math_rand_gauss(double sigma)
Definition gauss.c:15
#define x