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 52 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 = |
317 |
|
* evenly divisible by the range. The loop rejects candidates |
318 |
|
* computed from otherwise over-represented values. The |
319 |
|
* expected number of iterations under an ideal generator |
320 |
< |
* varies from 1 to 2, depending on the bound. |
320 |
> |
* varies from 1 to 2, depending on the bound. The loop itself |
321 |
> |
* takes an unlovable form. Because the first candidate is |
322 |
> |
* already available, we need a break-in-the-middle |
323 |
> |
* construction, which is concisely but cryptically performed |
324 |
> |
* within the while-condition of a body-less for loop. |
325 |
|
* |
326 |
|
* 4. Otherwise, the range cannot be represented as a positive |
327 |
< |
* long. Repeatedly generate unbounded longs until obtaining |
328 |
< |
* a candidate meeting constraints (with an expected number of |
329 |
< |
* iterations of less than two). |
327 |
> |
* long. The loop repeatedly generates unbounded longs until |
328 |
> |
* obtaining a candidate meeting constraints (with an expected |
329 |
> |
* number of iterations of less than two). |
330 |
|
*/ |
331 |
|
|
332 |
|
long r = mix64(nextSeed()); |
386 |
|
* @return a pseudorandom value |
387 |
|
*/ |
388 |
|
final double internalNextDouble(double origin, double bound) { |
389 |
< |
long bits = (1023L << 52) | (nextLong() >>> 12); |
380 |
< |
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); |
545 |
< |
return Double.longBitsToDouble(bits) - 1.0; |
553 |
> |
return (nextLong() >>> 11) * DOUBLE_UNIT; |
554 |
|
} |
555 |
|
|
556 |
|
/** |
877 |
|
|
878 |
|
public int characteristics() { |
879 |
|
return (Spliterator.SIZED | Spliterator.SUBSIZED | |
880 |
< |
Spliterator.ORDERED | Spliterator.NONNULL | |
873 |
< |
Spliterator.IMMUTABLE); |
880 |
> |
Spliterator.NONNULL | Spliterator.IMMUTABLE); |
881 |
|
} |
882 |
|
|
883 |
|
public boolean tryAdvance(IntConsumer consumer) { |
931 |
|
|
932 |
|
public int characteristics() { |
933 |
|
return (Spliterator.SIZED | Spliterator.SUBSIZED | |
934 |
< |
Spliterator.ORDERED | Spliterator.NONNULL | |
928 |
< |
Spliterator.IMMUTABLE); |
934 |
> |
Spliterator.NONNULL | Spliterator.IMMUTABLE); |
935 |
|
} |
936 |
|
|
937 |
|
public boolean tryAdvance(LongConsumer consumer) { |
986 |
|
|
987 |
|
public int characteristics() { |
988 |
|
return (Spliterator.SIZED | Spliterator.SUBSIZED | |
989 |
< |
Spliterator.ORDERED | Spliterator.NONNULL | |
984 |
< |
Spliterator.IMMUTABLE); |
989 |
> |
Spliterator.NONNULL | Spliterator.IMMUTABLE); |
990 |
|
} |
991 |
|
|
992 |
|
public boolean tryAdvance(DoubleConsumer consumer) { |