aboutsummaryrefslogtreecommitdiff
path: root/src/random.c
blob: f6cf85ea8c1252376c1fc7a4ed04cdac86336cf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "random.h"
#include <math.h>

double randn(void)
{
    /* Generates a random number from a normal distribution using the
     * Box-Muller transform. */
    double u1, u2;

    u1 = genrand_real1();
    u2 = genrand_real1();

    return sqrt(-2*log(u1))*cos(2*M_PI*u2);
}