MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / nrandf

Method nrandf

source/core/StarRandom.cpp:149–159  ·  view source on GitHub ↗

normal distribution via Box-Muller

Source from the content-addressed store, hash-verified

147
148// normal distribution via Box-Muller
149float RandomSource::nrandf(float stddev, float mean) {
150 float rand1, rand2, distSqr;
151 do {
152 rand1 = 2 * randf() - 1;
153 rand2 = 2 * randf() - 1;
154 distSqr = rand1 * rand1 + rand2 * rand2;
155 } while (distSqr >= 1);
156
157 float mapping = std::sqrt(-2 * std::log(distSqr) / distSqr);
158 return (rand1 * mapping * stddev + mean);
159}
160
161double RandomSource::nrandd(double stddev, double mean) {
162 double rand1, rand2, distSqr;

Callers 2

nrandfFunction · 0.80
TESTFunction · 0.80

Calls 1

randfFunction · 0.85

Tested by 1

TESTFunction · 0.64