Pseudo-randomly generates (approximately) a normally distributed double value with mean 0.0 and a standard deviation value of 1.0 using the polar method of G. E. P. Box, M. E. Muller, and G. Marsaglia, as described by Donald E. Knuth in The Art of Computer Programming, Volum
()
| 163 | * @see #nextDouble |
| 164 | */ |
| 165 | public synchronized double nextGaussian() { |
| 166 | if (haveNextNextGaussian) { // if X1 has been returned, return the |
| 167 | // second Gaussian |
| 168 | haveNextNextGaussian = false; |
| 169 | return nextNextGaussian; |
| 170 | } |
| 171 | |
| 172 | double v1, v2, s; |
| 173 | do { |
| 174 | v1 = 2 * nextDouble() - 1; // Generates two independent random |
| 175 | // variables U1, U2 |
| 176 | v2 = 2 * nextDouble() - 1; |
| 177 | s = v1 * v1 + v2 * v2; |
| 178 | } while (s >= 1); |
| 179 | double norm = Math.sqrt(-2 * Math.log(s) / s); |
| 180 | nextNextGaussian = v2 * norm; // should that not be norm instead |
| 181 | // of multiplier ? |
| 182 | haveNextNextGaussian = true; |
| 183 | return v1 * norm; // should that not be norm instead of multiplier |
| 184 | // ? |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Generates a uniformly distributed 32-bit {@code int} value from |
nothing calls this directly
no test coverage detected