MCPcopy Create free account
hub / github.com/NanoComp/meep / gaussian_random

Function gaussian_random

src/random.cpp:57–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57double gaussian_random(double mean, double stddev) {
58 init_rand();
59 // Box-Muller algorithm to generate Gaussian from uniform
60 // see Knuth vol II algorithm P, sec. 3.4.1
61 double v1, v2, s;
62 do {
63 v1 = 2 * meep_mt_genrand_res53() - 1;
64 v2 = 2 * meep_mt_genrand_res53() - 1;
65 s = v1 * v1 + v2 * v2;
66 } while (s >= 1.0);
67 if (s == 0) { return mean; }
68 else { return mean + v1 * sqrt(-2 * log(s) / s) * stddev; }
69}
70
71} // namespace meep

Callers 1

LOOP_OVER_VOL_OWNEDFunction · 0.85

Calls 2

init_randFunction · 0.85
meep_mt_genrand_res53Function · 0.85

Tested by

no test coverage detected