aboutsummaryrefslogtreecommitdiff
path: root/random/src
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2023-02-04 18:17:39 -0800
committer3gg <3gg@shellblade.net>2023-02-04 18:17:39 -0800
commit75abeca4a9d606bee89a41475f2f451187fec127 (patch)
tree348c29304d2500f87ebce81b5ce843793d53ee68 /random/src
parent90183beeb914590a2ea4eff0242b813562d2d641 (diff)
More compliance with C11.
Diffstat (limited to 'random/src')
-rw-r--r--random/src/normal.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/random/src/normal.c b/random/src/normal.c
index d4bcac1..5978274 100644
--- a/random/src/normal.c
+++ b/random/src/normal.c
@@ -2,16 +2,18 @@
2 2
3#include <math.h> 3#include <math.h>
4 4
5#define PI 3.14159265359
6
5// Generate two samples in the standard normal distribution using the 7// Generate two samples in the standard normal distribution using the
6// Box-Muller transform. 8// Box-Muller transform.
7// https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform 9// https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
8void normal2(double u, double v, double* z0, double* z1) { 10void normal2(double u, double v, double* z0, double* z1) {
9 const double r = sqrt(-2 * log(u)); 11 const double r = sqrt(-2 * log(u));
10 const double x = 2 * M_PI * v; 12 const double x = 2 * PI * v;
11 *z0 = r * cos(x); 13 *z0 = r * cos(x);
12 *z1 = r * sin(x); 14 *z1 = r * sin(x);
13} 15}
14 16
15double normal_transform(double z, double mu, double sigma) { 17double normal_transform(double z, double mu, double sigma) {
16 return z*sigma + mu; 18 return z * sigma + mu;
17} 19}