178 |
|
private static final long DEFAULT_SEED_GAMMA = 0xBD24B73A95FB84D9L; |
179 |
|
|
180 |
|
/** |
181 |
+ |
* The least non-zero value returned by nextDouble(). This value |
182 |
+ |
* is scaled by a random value of 53 bits to produce a result. |
183 |
+ |
*/ |
184 |
+ |
private static final double DOUBLE_UNIT = 1.0 / (1L << 53); |
185 |
+ |
|
186 |
+ |
/** |
187 |
|
* The next seed for default constructors. |
188 |
|
*/ |
189 |
|
private static final AtomicLong defaultSeedGenerator = |
386 |
|
* @return a pseudorandom value |
387 |
|
*/ |
388 |
|
final double internalNextDouble(double origin, double bound) { |
389 |
< |
long bits = (1023L << 52) | (nextLong() >>> 12); |
384 |
< |
double r = Double.longBitsToDouble(bits) - 1.0; |
389 |
> |
double r = (nextLong() >>> 11) * DOUBLE_UNIT; |
390 |
|
if (origin < bound) { |
391 |
|
r = r * (bound - origin) + origin; |
392 |
|
if (r == bound) // correct for rounding |
550 |
|
* (inclusive) and {@code 1.0} (exclusive) |
551 |
|
*/ |
552 |
|
public double nextDouble() { |
553 |
< |
long bits = (1023L << 52) | (nextLong() >>> 12); |
549 |
< |
return Double.longBitsToDouble(bits) - 1.0; |
553 |
> |
return (nextLong() >>> 11) * DOUBLE_UNIT; |
554 |
|
} |
555 |
|
|
556 |
|
/** |