ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/SplittableRandom.java
(Generate patch)

Comparing jsr166/src/main/java/util/SplittableRandom.java (file contents):
Revision 1.4 by dl, Thu Jul 11 13:40:42 2013 UTC vs.
Revision 1.5 by dl, Thu Jul 11 23:14:45 2013 UTC

# Line 178 | Line 178 | public class SplittableRandom {
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 =
# Line 380 | Line 386 | public class SplittableRandom {
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
# Line 545 | Line 550 | public class SplittableRandom {
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      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines