aboutsummaryrefslogtreecommitdiff
path: root/src/random.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/random.c')
-rw-r--r--src/random.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/random.c b/src/random.c
new file mode 100644
index 0000000..f6cf85e
--- /dev/null
+++ b/src/random.c
@@ -0,0 +1,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);
+}