[cvs] / jsr166 / src / main / java / util / SplittableRandom.java Repository:
ViewVC logotype

Diff of /jsr166/src/main/java/util/SplittableRandom.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4, Thu Jul 11 13:40:42 2013 UTC revision 1.5, Thu Jul 11 23:14:45 2013 UTC
# Line 178  Line 178 
178      private static final long DEFAULT_SEED_GAMMA = 0xBD24B73A95FB84D9L;      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.       * The next seed for default constructors.
188       */       */
189      private static final AtomicLong defaultSeedGenerator =      private static final AtomicLong defaultSeedGenerator =
# Line 380  Line 386 
386       * @return a pseudorandom value       * @return a pseudorandom value
387       */       */
388      final double internalNextDouble(double origin, double bound) {      final double internalNextDouble(double origin, double bound) {
389          long bits = (1023L << 52) | (nextLong() >>> 12);          double r = (nextLong() >>> 11) * DOUBLE_UNIT;
         double r = Double.longBitsToDouble(bits) - 1.0;  
390          if (origin < bound) {          if (origin < bound) {
391              r = r * (bound - origin) + origin;              r = r * (bound - origin) + origin;
392              if (r == bound) // correct for rounding              if (r == bound) // correct for rounding
# Line 545  Line 550 
550       * (inclusive) and {@code 1.0} (exclusive)       * (inclusive) and {@code 1.0} (exclusive)
551       */       */
552      public double nextDouble() {      public double nextDouble() {
553          long bits = (1023L << 52) | (nextLong() >>> 12);          return (nextLong() >>> 11) * DOUBLE_UNIT;
         return Double.longBitsToDouble(bits) - 1.0;  
554      }      }
555    
556      /**      /**

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8