(mu, sigma)
| 14475 | |
| 14476 | var 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 |
no test coverage detected