MCPcopy Create free account
hub / github.com/breck7/scroll / randomNormal

Function randomNormal

external/.d3.js:14477–14496  ·  view source on GitHub ↗
(mu, sigma)

Source from the content-addressed store, hash-verified

14475
14476var normal = (function sourceRandomNormal(source) {
14477 function randomNormal(mu, sigma) {
14478 var x, r;
14479 mu = mu == null ? 0 : +mu;
14480 sigma = sigma == null ? 1 : +sigma;
14481 return function() {
14482 var y;
14483
14484 // If available, use the second previously-generated uniform random.
14485 if (x != null) y = x, x = null;
14486
14487 // Otherwise, generate a new x and y.
14488 else do {
14489 x = source() * 2 - 1;
14490 y = source() * 2 - 1;
14491 r = x * x + y * y;
14492 } while (!r || r > 1);
14493
14494 return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
14495 };
14496 }
14497
14498 randomNormal.source = sourceRandomNormal;
14499

Callers 2

randomLogNormalFunction · 0.85
randomGammaFunction · 0.85

Calls 1

logMethod · 0.80

Tested by

no test coverage detected