src/java.base/share/classes/java/util/random/Xoroshiro128StarStar.java
branchJDK-8193209-branch
changeset 59080 1b314be4feb2
parent 57547 56cbdc3ea079
equal deleted inserted replaced
57940:7e791393cc4d 59080:1b314be4feb2
   152     public Xoroshiro128StarStar(long x0, long x1) {
   152     public Xoroshiro128StarStar(long x0, long x1) {
   153         this.x0 = x0;
   153         this.x0 = x0;
   154         this.x1 = x1;
   154         this.x1 = x1;
   155         // If x0 and x1 are both zero, we must choose nonzero values.
   155         // If x0 and x1 are both zero, we must choose nonzero values.
   156         if ((x0 | x1) == 0) {
   156         if ((x0 | x1) == 0) {
   157             // At least one of the two values generated here will be nonzero.
   157             this.x0 = RandomSupport.GOLDEN_RATIO_64;
   158             this.x0 = RandomSupport.mixStafford13(x0 += RandomSupport.GOLDEN_RATIO_64);
   158             this.x1 = RandomSupport.SILVER_RATIO_64;
   159             this.x1 = (x0 += RandomSupport.GOLDEN_RATIO_64);
       
   160         }
   159         }
   161     }
   160     }
   162 
   161 
   163     /**
   162     /**
   164      * Creates a new instance of {@link Xoroshiro128StarStar} using the
   163      * Creates a new instance of {@link Xoroshiro128StarStar} using the
   242      * @return a pseudorandom {@code long} value
   241      * @return a pseudorandom {@code long} value
   243      */
   242      */
   244     public long nextLong() {
   243     public long nextLong() {
   245         final long s0 = x0;
   244         final long s0 = x0;
   246         long s1 = x1;
   245         long s1 = x1;
   247         final long z = s0;
   246 	// Compute the result based on current state information
       
   247 	// (this allows the computation to be overlapped with state update).
       
   248         final long result = Long.rotateLeft(s0 * 5, 7) * 9;  // "starstar" mixing function
   248 
   249 
   249         s1 ^= s0;
   250         s1 ^= s0;
   250         x0 = Long.rotateLeft(s0, 24) ^ s1 ^ (s1 << 16); // a, b
   251         x0 = Long.rotateLeft(s0, 24) ^ s1 ^ (s1 << 16); // a, b
   251         x1 = Long.rotateLeft(s1, 37); // c
   252         x1 = Long.rotateLeft(s1, 37); // c
   252 
   253 
   253         return Long.rotateLeft(z * 5, 7) * 9;  // "starstar" mixing function
   254         return result;
   254     }
   255     }
   255 
   256 
   256     public BigInteger period() {
   257     public BigInteger period() {
   257         return PERIOD;
   258         return PERIOD;
   258     }
   259     }