src/java.base/share/classes/java/util/random/L32X64MixRandom.java
branchJDK-8193209-branch
changeset 57684 7cb325557832
parent 57547 56cbdc3ea079
equal deleted inserted replaced
57671:6a4be8bf8990 57684:7cb325557832
    59  * (and {@link L32X64MixRandom} does use a mixing function).
    59  * (and {@link L32X64MixRandom} does use a mixing function).
    60  * <p>
    60  * <p>
    61  * The LCG subgenerator for {@link L32X64MixRandom} has an update step of the
    61  * The LCG subgenerator for {@link L32X64MixRandom} has an update step of the
    62  * form {@code s = m * s + a}, where {@code s}, {@code m}, and {@code a} are all
    62  * form {@code s = m * s + a}, where {@code s}, {@code m}, and {@code a} are all
    63  * of type {@code int}; {@code s} is the mutable state, the multiplier {@code m}
    63  * of type {@code int}; {@code s} is the mutable state, the multiplier {@code m}
    64  * is fixed (the same for all instances of {@link L32X64MixRandom}}) and the addend
    64  * is fixed (the same for all instances of {@link L32X64MixRandom}) and the addend
    65  * {@code a} is a parameter (a final field of the instance).  The parameter
    65  * {@code a} is a parameter (a final field of the instance).  The parameter
    66  * {@code a} is required to be odd (this allows the LCG to have the maximal
    66  * {@code a} is required to be odd (this allows the LCG to have the maximal
    67  * period, namely 2<sup>32</sup>); therefore there are 2<sup>31</sup> distinct choices
    67  * period, namely 2<sup>32</sup>); therefore there are 2<sup>31</sup> distinct choices
    68  * of parameter.
    68  * of parameter.
    69  * <p>
    69  * <p>
   288      * values were generated by a single thread using a single {@link L32X64MixRandom} object.
   288      * values were generated by a single thread using a single {@link L32X64MixRandom} object.
   289      * Either or both of the two objects may be further split using the {@code split} method, and
   289      * Either or both of the two objects may be further split using the {@code split} method, and
   290      * the same expected statistical properties apply to the entire set of generators constructed by
   290      * the same expected statistical properties apply to the entire set of generators constructed by
   291      * such recursive splitting.
   291      * such recursive splitting.
   292      *
   292      *
   293      * @param source a {@link SplittableGenerator} instance to be used instead of this one as a source of
   293      * @param source a {@link SplittableGenerator} instance to be used instead of this one as
   294      *               pseudorandom bits used to initialize the state of the new ones.
   294      *               a source of pseudorandom bits used to initialize the state of the new ones.
   295      *
   295      *
   296      * @return a new instance of {@link L32X64MixRandom}
   296      * @return a new instance of {@link L32X64MixRandom}
   297      */
   297      */
   298     public L32X64MixRandom split(SplittableGenerator source) {
   298     public L32X64MixRandom split(SplittableGenerator source) {
   299         // Literally pick a new instance "at random".
   299         // Literally pick a new instance "at random".
   308      */
   308      */
   309     public int nextInt() {
   309     public int nextInt() {
   310         final int z = s + x0;
   310         final int z = s + x0;
   311         s = M * s + a;  // LCG
   311         s = M * s + a;  // LCG
   312         int q0 = x0, q1 = x1;
   312         int q0 = x0, q1 = x1;
   313         { q1 ^= q0; q0 = Integer.rotateLeft(q0, 26); q0 = q0 ^ q1 ^ (q1 << 9); q1 = Integer.rotateLeft(q1, 13); }  // xoroshiro64
   313         {   // xoroshiro64
       
   314             q1 ^= q0;
       
   315             q0 = Integer.rotateLeft(q0, 26);
       
   316             q0 = q0 ^ q1 ^ (q1 << 9);
       
   317             q1 = Integer.rotateLeft(q1, 13);
       
   318         }
   314         x0 = q0; x1 = q1;
   319         x0 = q0; x1 = q1;
   315         return Integer.rotateLeft(z * 5, 7) * 9;  // "starstar" mixing function
   320         return Integer.rotateLeft(z * 5, 7) * 9;  // "starstar" mixing function
   316     }
   321     }
   317 
   322 
   318     /**
   323     /**