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.23 by dl, Fri Sep 20 14:06:46 2013 UTC vs.
Revision 1.24 by dl, Mon Oct 7 10:54:27 2013 UTC

# Line 110 | Line 110 | public final class SplittableRandom {
110       * For nextLong, the mix64 function is based on David Stafford's
111       * (http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html)
112       * "Mix13" variant of the "64-bit finalizer" function in Austin
113 <     * Appleby's MurmurHash3 algorithm See
114 <     * http://code.google.com/p/smhasher/wiki/MurmurHash3 . The mix32
113 >     * Appleby's MurmurHash3 algorithm (see
114 >     * http://code.google.com/p/smhasher/wiki/MurmurHash3). The mix32
115       * function is based on Stafford's Mix04 mix function, but returns
116       * the upper 32 bits cast as int.
117       *
# Line 166 | Line 166 | public final class SplittableRandom {
166       * The least non-zero value returned by nextDouble(). This value
167       * is scaled by a random value of 53 bits to produce a result.
168       */
169 <    private static final double DOUBLE_ULP = 1.0 / (1L << 53);
169 >    private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53);
170  
171      /**
172       * The seed. Updated only via method nextSeed.
# Line 190 | Line 190 | public final class SplittableRandom {
190       * Computes Stafford variant 13 of 64bit mix function.
191       */
192      private static long mix64(long z) {
193 <        z *= 0xbf58476d1ce4e5b9L;
194 <        z = (z ^ (z >>> 32)) * 0x94d049bb133111ebL;
195 <        return z ^ (z >>> 32);
193 >        z = (z ^ (z >>> 30)) * 0xbf58476d1ce4e5b9L;
194 >        z = (z ^ (z >>> 27)) * 0x94d049bb133111ebL;
195 >        return z ^ (z >>> 31);
196      }
197  
198      /**
199       * Returns the 32 high bits of Stafford variant 4 mix64 function as int.
200       */
201      private static int mix32(long z) {
202 <        z *= 0x62a9d9ed799705f5L;
202 >        z = (z ^ (z >>> 33)) * 0x62a9d9ed799705f5L;
203          return (int)(((z ^ (z >>> 28)) * 0xcb24d0a5c88c35b3L) >>> 32);
204      }
205  
# Line 207 | Line 207 | public final class SplittableRandom {
207       * Returns the gamma value to use for a new split instance.
208       */
209      private static long mixGamma(long z) {
210 <        z *= 0xff51afd7ed558ccdL;                   // MurmurHash3 mix constants
210 >        z = (z ^ (z >>> 33)) * 0xff51afd7ed558ccdL; // MurmurHash3 mix constants
211          z = (z ^ (z >>> 33)) * 0xc4ceb9fe1a85ec53L;
212          z = (z ^ (z >>> 33)) | 1L;                  // force to be odd
213          int n = Long.bitCount(z ^ (z >>> 1));       // ensure enough transitions
# Line 373 | Line 373 | public final class SplittableRandom {
373       * @return a pseudorandom value
374       */
375      final double internalNextDouble(double origin, double bound) {
376 <        double r = (nextLong() >>> 11) * DOUBLE_ULP;
376 >        double r = (nextLong() >>> 11) * DOUBLE_UNIT;
377          if (origin < bound) {
378              r = r * (bound - origin) + origin;
379              if (r >= bound) // correct for rounding
# Line 537 | Line 537 | public final class SplittableRandom {
537       *         (inclusive) and one (exclusive)
538       */
539      public double nextDouble() {
540 <        return (mix64(nextSeed()) >>> 11) * DOUBLE_ULP;
540 >        return (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT;
541      }
542  
543      /**
# Line 552 | Line 552 | public final class SplittableRandom {
552      public double nextDouble(double bound) {
553          if (!(bound > 0.0))
554              throw new IllegalArgumentException(BadBound);
555 <        double result = (mix64(nextSeed()) >>> 11) * DOUBLE_ULP * bound;
555 >        double result = (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT * bound;
556          return (result < bound) ?  result : // correct for rounding
557              Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
558      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines