src/java.base/share/classes/java/util/random/L64X256Random.java
branchJDK-8193209-branch
changeset 57437 f02ffcb61dce
parent 57436 b0c958c0e6c6
child 57547 56cbdc3ea079
equal deleted inserted replaced
57436:b0c958c0e6c6 57437:f02ffcb61dce
    20  *
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 package java.util;
    25 
       
    26 package java.util.random;
    26 
    27 
    27 import java.math.BigInteger;
    28 import java.math.BigInteger;
    28 import java.util.concurrent.atomic.AtomicLong;
    29 import java.util.concurrent.atomic.AtomicLong;
    29 
    30 
    30 /**
    31 /**
    31  * A generator of uniform pseudorandom values applicable for use in
    32  * A generator of uniform pseudorandom values applicable for use in
    32  * (among other contexts) isolated parallel computations that may
    33  * (among other contexts) isolated parallel computations that may
    33  * generate subtasks.  Class {@code L64X256Random} implements
    34  * generate subtasks.  Class {@link L64X256Random} implements
    34  * interfaces {@link java.util.Rng} and {@link java.util.SplittableRng},
    35  * interfaces {@link RandomNumberGenerator} and {@link SplittableRNG},
    35  * and therefore supports methods for producing pseudorandomly chosen
    36  * and therefore supports methods for producing pseudorandomly chosen
    36  * numbers of type {@code int}, {@code long}, {@code float}, and {@code double}
    37  * numbers of type {@code int}, {@code long}, {@code float}, and {@code double}
    37  * as well as creating new split-off {@code L64X256Random} objects,
    38  * as well as creating new split-off {@link L64X256Random} objects,
    38  * with similar usages as for class {@link java.util.SplittableRandom}.
    39  * with similar usages as for class {@link java.util.SplittableRandom}.
    39  *
    40  * <p>
    40  * <p>Series of generated values pass the TestU01 BigCrush and PractRand test suites
    41  * Series of generated values pass the TestU01 BigCrush and PractRand test suites
    41  * that measure independence and uniformity properties of random number generators.
    42  * that measure independence and uniformity properties of random number generators.
    42  * (Most recently validated with
    43  * (Most recently validated with
    43  * <a href="http://simul.iro.umontreal.ca/testu01/tu01.html">version 1.2.3 of TestU01</a>
    44  * <a href="http://simul.iro.umontreal.ca/testu01/tu01.html">version 1.2.3 of TestU01</a>
    44  * and <a href="http://pracrand.sourceforge.net">version 0.90 of PractRand</a>.
    45  * and <a href="http://pracrand.sourceforge.net">version 0.90 of PractRand</a>.
    45  * Note that TestU01 BigCrush was used to test not only values produced by the {@code nextLong()}
    46  * Note that TestU01 BigCrush was used to test not only values produced by the {@code nextLong()}
    46  * method but also the result of bit-reversing each value produced by {@code nextLong()}.)
    47  * method but also the result of bit-reversing each value produced by {@code nextLong()}.)
    47  * These tests validate only the methods for certain
    48  * These tests validate only the methods for certain
    48  * types and ranges, but similar properties are expected to hold, at
    49  * types and ranges, but similar properties are expected to hold, at
    49  * least approximately, for others as well.
    50  * least approximately, for others as well.
    50  *
    51  * <p>
    51  * <p>{@code L64X256Random} is a specific member of the LXM family of algorithms
    52  * {@link L64X256Random} is a specific member of the LXM family of algorithms
    52  * for pseudorandom number generators.  Every LXM generator consists of two
    53  * for pseudorandom number generators.  Every LXM generator consists of two
    53  * subgenerators; one is an LCG (Linear Congruential Generator) and the other is
    54  * subgenerators; one is an LCG (Linear Congruential Generator) and the other is
    54  * an Xorshift generator.  Each output of an LXM generator is the sum of one
    55  * an Xorshift generator.  Each output of an LXM generator is the sum of one
    55  * output from each subgenerator, possibly processed by a final mixing function
    56  * output from each subgenerator, possibly processed by a final mixing function
    56  * (but {@code L64X256Random} does not use a mixing function).
    57  * (but {@link L64X256Random} does not use a mixing function).
    57  *
    58  * <p>
    58  * <p>The LCG subgenerator for {@code L64X256Random} has an update step of the
    59  * The LCG subgenerator for {@link L64X256Random} has an update step of the
    59  * form {@code s = m * s + a}, where {@code s}, {@code m}, and {@code a} are all
    60  * form {@code s = m * s + a}, where {@code s}, {@code m}, and {@code a} are all
    60  * of type {@code long}; {@code s} is the mutable state, the multiplier {@code m}
    61  * of type {@code long}; {@code s} is the mutable state, the multiplier {@code m}
    61  * is fixed (the same for all instances of {@code L64X256Random}}) and the addend
    62  * is fixed (the same for all instances of {@link L64X256Random}}) and the addend
    62  * {@code a} is a parameter (a final field of the instance).  The parameter
    63  * {@code a} is a parameter (a final field of the instance).  The parameter
    63  * {@code a} is required to be odd (this allows the LCG to have the maximal
    64  * {@code a} is required to be odd (this allows the LCG to have the maximal
    64  * period, namely 2<sup>64</sup>); therefore there are 2<sup>63</sup> distinct choices
    65  * period, namely 2<sup>64</sup>); therefore there are 2<sup>63</sup> distinct choices
    65  * of parameter.
    66  * of parameter.
    66  *
    67  * <p>
    67  * <p>The Xorshift subgenerator for {@code L64X256Random} is the {@code xoshiro256} algorithm,
    68  * The Xorshift subgenerator for {@link L64X256Random} is the {@code xoshiro256} algorithm,
    68  * version 1.0 (parameters 17, 45), without any final scrambler such as "+" or "**".
    69  * version 1.0 (parameters 17, 45), without any final scrambler such as "+" or "**".
    69  * Its state consists of four {@code long} fields {@code x0}, {@code x1}, {@code x2},
    70  * Its state consists of four {@code long} fields {@code x0}, {@code x1}, {@code x2},
    70  * and {@code x3}, which can take on any values provided that they are not all zero.
    71  * and {@code x3}, which can take on any values provided that they are not all zero.
    71  * The period of this subgenerator is 2<sup>256</sup>-1.
    72  * The period of this subgenerator is 2<sup>256</sup>-1.
    72  *
    73  * <p>
    73  * <p> Because the periods 2<sup>64</sup> and 2<sup>256</sup>-1 of the two subgenerators
    74  * Because the periods 2<sup>64</sup> and 2<sup>256</sup>-1 of the two subgenerators
    74  * are relatively prime, the <em>period</em> of any single {@code L64X256Random} object 
    75  * are relatively prime, the <em>period</em> of any single {@link L64X256Random} object
    75  * (the length of the series of generated 64-bit values before it repeats) is the product
    76  * (the length of the series of generated 64-bit values before it repeats) is the product
    76  * of the periods of the subgenerators, that is, 2<sup>64</sup>(2<sup>256</sup>-1),
    77  * of the periods of the subgenerators, that is, 2<sup>64</sup>(2<sup>256</sup>-1),
    77  * which is just slightly smaller than 2<sup>320</sup>.  Moreover, if two distinct
    78  * which is just slightly smaller than 2<sup>320</sup>.  Moreover, if two distinct
    78  * {@code L64X256Random} objects have different {@code a} parameters, then their
    79  * {@link L64X256Random} objects have different {@code a} parameters, then their
    79  * cycles of produced values will be different.
    80  * cycles of produced values will be different.
    80  *
    81  * <p>
    81  * <p>The 64-bit values produced by the {@code nextLong()} method are exactly equidistributed.
    82  * The 64-bit values produced by the {@code nextLong()} method are exactly equidistributed.
    82  * For any specific instance of {@code L64X256Random}, over the course of its cycle each
    83  * For any specific instance of {@link L64X256Random}, over the course of its cycle each
    83  * of the 2<sup>64</sup> possible {@code long} values will be produced 2<sup>256</sup>-1 times.
    84  * of the 2<sup>64</sup> possible {@code long} values will be produced 2<sup>256</sup>-1 times.
    84  * The values produced by the {@code nextInt()}, {@code nextFloat()}, and {@code nextDouble()}
    85  * The values produced by the {@code nextInt()}, {@code nextFloat()}, and {@code nextDouble()}
    85  * methods are likewise exactly equidistributed.
    86  * methods are likewise exactly equidistributed.
    86  *
    87  * <p>
    87  * <p> In fact, the 64-bit values produced by the {@code nextLong()} method are 4-equidistributed.
    88  * In fact, the 64-bit values produced by the {@code nextLong()} method are 4-equidistributed.
    88  * To be precise: for any specific instance of {@code L64X256Random}, consider
    89  * To be precise: for any specific instance of {@link L64X256Random}, consider
    89  * the (overlapping) length-4 subsequences of the cycle of 64-bit values produced by
    90  * the (overlapping) length-4 subsequences of the cycle of 64-bit values produced by
    90  * {@code nextLong()} (assuming no other methods are called that would affect the state).
    91  * {@code nextLong()} (assuming no other methods are called that would affect the state).
    91  * There are 2<sup>64</sup>(2<sup>256</sup>-1) such subsequences, and each subsequence,
    92  * There are 2<sup>64</sup>(2<sup>256</sup>-1) such subsequences, and each subsequence,
    92  * which consists of 4 64-bit values, can have one of 2<sup>256</sup> values. Of those
    93  * which consists of 4 64-bit values, can have one of 2<sup>256</sup> values. Of those
    93  * 2<sup>256</sup> subsequence values, nearly all of them (2<sup>256</sup>-2<sup>64</sup>)
    94  * 2<sup>256</sup> subsequence values, nearly all of them (2<sup>256</sup>-2<sup>64</sup>)
    94  * occur 2<sup>64</sup> times over the course of the entire cycle, and the other
    95  * occur 2<sup>64</sup> times over the course of the entire cycle, and the other
    95  * 2<sup>64</sup> subsequence values occur only 2<sup>64</sup>-1 times.  So the ratio
    96  * 2<sup>64</sup> subsequence values occur only 2<sup>64</sup>-1 times.  So the ratio
    96  * of the probability of getting one of the less common subsequence values and the
    97  * of the probability of getting one of the less common subsequence values and the
    97  * probability of getting one of the more common subsequence values is 1-2<sup>-64</sup>.
    98  * probability of getting one of the more common subsequence values is 1-2<sup>-64</sup>.
    98  * (Note that the set of 2<sup>64</sup> less-common subsequence values will differ from
    99  * (Note that the set of 2<sup>64</sup> less-common subsequence values will differ from
    99  * one instance of {@code L64X256Random} to another, as a function of the additive
   100  * one instance of {@link L64X256Random} to another, as a function of the additive
   100  * parameter of the LCG.)  The values produced by the {@code nextInt()}, {@code nextFloat()},
   101  * parameter of the LCG.)  The values produced by the {@code nextInt()}, {@code nextFloat()},
   101  * and {@code nextDouble()} methods are likewise 4-equidistributed.
   102  * and {@code nextDouble()} methods are likewise 4-equidistributed.
   102  *
   103  * <p>
   103  * <p>Method {@link #split} constructs and returns a new {@code L64X256Random}
   104  * Method {@link #split} constructs and returns a new {@link L64X256Random}
   104  * instance that shares no mutable state with the current instance. However, with
   105  * instance that shares no mutable state with the current instance. However, with
   105  * very high probability, the values collectively generated by the two objects
   106  * very high probability, the values collectively generated by the two objects
   106  * have the same statistical properties as if the same quantity of values were
   107  * have the same statistical properties as if the same quantity of values were
   107  * generated by a single thread using a single {@code L64X256Random} object.
   108  * generated by a single thread using a single {@link L64X256Random} object.
   108  * This is because, with high probability, distinct {@code L64X256Random} objects
   109  * This is because, with high probability, distinct {@link L64X256Random} objects
   109  * have distinct {@code a} parameters and therefore use distinct members of the
   110  * have distinct {@code a} parameters and therefore use distinct members of the
   110  * algorithmic family; and even if their {@code a} parameters are the same, with
   111  * algorithmic family; and even if their {@code a} parameters are the same, with
   111  * very high probability they will traverse different parts of their common state
   112  * very high probability they will traverse different parts of their common state
   112  * cycle.
   113  * cycle.
   113  *
   114  * <p>
   114  * <p>As with {@link java.util.SplittableRandom}, instances of
   115  * As with {@link java.util.SplittableRandom}, instances of
   115  * {@code L64X256Random} are <em>not</em> thread-safe.
   116  * {@link L64X256Random} are <em>not</em> thread-safe.
   116  * They are designed to be split, not shared, across threads. For
   117  * They are designed to be split, not shared, across threads. For
   117  * example, a {@link java.util.concurrent.ForkJoinTask} fork/join-style
   118  * example, a {@link java.util.concurrent.ForkJoinTask} fork/join-style
   118  * computation using random numbers might include a construction
   119  * computation using random numbers might include a construction
   119  * of the form {@code new Subtask(someL64X256Random.split()).fork()}.
   120  * of the form {@code new Subtask(someL64X256Random.split()).fork()}.
   120  *
   121  * <p>
   121  * <p>This class provides additional methods for generating random
   122  * This class provides additional methods for generating random
   122  * streams, that employ the above techniques when used in
   123  * streams, that employ the above techniques when used in
   123  * {@code stream.parallel()} mode.
   124  * {@code stream.parallel()} mode.
   124  *
   125  * <p>
   125  * <p>Instances of {@code L64X256Random} are not cryptographically
   126  * Instances of {@link L64X256Random} are not cryptographically
   126  * secure.  Consider instead using {@link java.security.SecureRandom}
   127  * secure.  Consider instead using {@link java.security.SecureRandom}
   127  * in security-sensitive applications. Additionally,
   128  * in security-sensitive applications. Additionally,
   128  * default-constructed instances do not use a cryptographically random
   129  * default-constructed instances do not use a cryptographically random
   129  * seed unless the {@linkplain System#getProperty system property}
   130  * seed unless the {@linkplain System#getProperty system property}
   130  * {@code java.util.secureRandomSeed} is set to {@code true}.
   131  * {@code java.util.secureRandomSeed} is set to {@code true}.
   131  *
   132  *
   132  * @author  Guy Steele
   133  * @since 14
   133  * @since   1.9
       
   134  */
   134  */
   135 public final class L64X256Random extends AbstractSplittableRng {
   135 public final class L64X256Random extends AbstractSplittableRNG {
   136 
   136 
   137     /*
   137     /*
   138      * Implementation Overview.
   138      * Implementation Overview.
   139      *
   139      *
   140      * The split() operation uses the current generator to choose six new 64-bit
   140      * The split() operation uses the current generator to choose six new 64-bit
   142      * state variables `s`, `x0`, `x1`, `x2`, and `x3` for a newly constructed
   142      * state variables `s`, `x0`, `x1`, `x2`, and `x3` for a newly constructed
   143      * generator.
   143      * generator.
   144      *
   144      *
   145      * With extremely high probability, no two generators so chosen
   145      * With extremely high probability, no two generators so chosen
   146      * will have the same `a` parameter, and testing has indicated
   146      * will have the same `a` parameter, and testing has indicated
   147      * that the values generated by two instances of {@code L64X256Random}
   147      * that the values generated by two instances of {@link L64X256Random}
   148      * will be (approximately) independent if have different values for `a`.
   148      * will be (approximately) independent if have different values for `a`.
   149      *
   149      *
   150      * The default (no-argument) constructor, in essence, uses
   150      * The default (no-argument) constructor, in essence, uses
   151      * "defaultGen" to generate six new 64-bit values for the same
   151      * "defaultGen" to generate six new 64-bit values for the same
   152      * purpose.  Multiple generators created in this way will certainly
   152      * purpose.  Multiple generators created in this way will certainly
   165     /* ---------------- static fields ---------------- */
   165     /* ---------------- static fields ---------------- */
   166 
   166 
   167     /**
   167     /**
   168      * The seed generator for default constructors.
   168      * The seed generator for default constructors.
   169      */
   169      */
   170     private static final AtomicLong defaultGen = new AtomicLong(RngSupport.initialSeed());
   170     private static final AtomicLong defaultGen = new AtomicLong(RNGSupport.initialSeed());
   171 
   171 
   172     /*
   172     /*
   173      * The period of this generator, which is (2**256 - 1) * 2**64.
   173      * The period of this generator, which is (2**256 - 1) * 2**64.
   174      */
   174      */
   175     private static final BigInteger thePeriod =
   175     private static final BigInteger PERIOD =
   176 	BigInteger.ONE.shiftLeft(256).subtract(BigInteger.ONE).shiftLeft(64);
   176         BigInteger.ONE.shiftLeft(256).subtract(BigInteger.ONE).shiftLeft(64);
   177 
   177 
   178     /*
   178     /*
   179      * Multiplier used in the LCG portion of the algorithm, taken from
   179      * Multiplier used in the LCG portion of the algorithm, taken from
   180      * Pierre L'Ecuyer, Tables of linear congruential generators of
   180      * Pierre L'Ecuyer, Tables of linear congruential generators of
   181      * different sizes and good lattice structure, <em>Mathematics of
   181      * different sizes and good lattice structure, <em>Mathematics of
   182      * Computation</em> 68, 225 (January 1999), pages 249-260,
   182      * Computation</em> 68, 225 (January 1999), pages 249-260,
   183      * Table 4 (first multiplier for size 2<sup>64</sup>).
   183      * Table 4 (first multiplier for size 2<sup>64</sup>).
   184      */
   184      */
   185 
   185 
   186     private static final long m = 2862933555777941757L;
   186     private static final long M = 2862933555777941757L;
   187 
   187 
   188     /* ---------------- instance fields ---------------- */
   188     /* ---------------- instance fields ---------------- */
   189 
   189 
   190     /**
   190     /**
   191      * The parameter that is used as an additive constant for the LCG.
   191      * The parameter that is used as an additive constant for the LCG.
   212      * @param x1 second word of the initial state for the xorshift generator
   212      * @param x1 second word of the initial state for the xorshift generator
   213      * @param x2 third word of the initial state for the xorshift generator
   213      * @param x2 third word of the initial state for the xorshift generator
   214      * @param x3 fourth word of the initial state for the xorshift generator
   214      * @param x3 fourth word of the initial state for the xorshift generator
   215      */
   215      */
   216     public L64X256Random(long a, long s, long x0, long x1, long x2, long x3) {
   216     public L64X256Random(long a, long s, long x0, long x1, long x2, long x3) {
   217 	// Force a to be odd.
   217         // Force a to be odd.
   218         this.a = a | 1;
   218         this.a = a | 1;
   219         this.s = s;
   219         this.s = s;
   220         this.x0 = x0;
   220         this.x0 = x0;
   221         this.x1 = x1;
   221         this.x1 = x1;
   222         this.x2 = x2;
   222         this.x2 = x2;
   223         this.x3 = x3;
   223         this.x3 = x3;
   224 	// If x0, x1, x2, and x3 are all zero, we must choose nonzero values.
   224         // If x0, x1, x2, and x3 are all zero, we must choose nonzero values.
   225         if ((x0 | x1 | x2 | x3) == 0) {
   225         if ((x0 | x1 | x2 | x3) == 0) {
   226 	    // At least three of the four values generated here will be nonzero.
   226             // At least three of the four values generated here will be nonzero.
   227 	    this.x0 = RngSupport.mixStafford13(s += RngSupport.GOLDEN_RATIO_64);
   227             this.x0 = RNGSupport.mixStafford13(s += RNGSupport.GOLDEN_RATIO_64);
   228 	    this.x1 = RngSupport.mixStafford13(s += RngSupport.GOLDEN_RATIO_64);
   228             this.x1 = RNGSupport.mixStafford13(s += RNGSupport.GOLDEN_RATIO_64);
   229 	    this.x2 = RngSupport.mixStafford13(s += RngSupport.GOLDEN_RATIO_64);
   229             this.x2 = RNGSupport.mixStafford13(s += RNGSupport.GOLDEN_RATIO_64);
   230 	    this.x3 = RngSupport.mixStafford13(s + RngSupport.GOLDEN_RATIO_64);
   230             this.x3 = RNGSupport.mixStafford13(s + RNGSupport.GOLDEN_RATIO_64);
   231 	}
   231         }
   232     }
   232     }
   233 
   233 
   234     /**
   234     /**
   235      * Creates a new instance of {@code L64X256Random} using the
   235      * Creates a new instance of {@link L64X256Random} using the
   236      * specified {@code long} value as the initial seed. Instances of
   236      * specified {@code long} value as the initial seed. Instances of
   237      * {@code L64X256Random} created with the same seed in the same
   237      * {@link L64X256Random} created with the same seed in the same
   238      * program execution generate identical sequences of values.
   238      * program execution generate identical sequences of values.
   239      *
   239      *
   240      * @param seed the initial seed
   240      * @param seed the initial seed
   241      */
   241      */
   242     public L64X256Random(long seed) {
   242     public L64X256Random(long seed) {
   243 	// Using a value with irregularly spaced 1-bit to xor the seed
   243         // Using a value with irregularly spaced 1-bit to xor the seed
   244 	// argument tends to improve "pedestrian" seeds such as 0 or
   244         // argument tends to improve "pedestrian" seeds such as 0 or
   245 	// other small integers.  We may as well use SILVER_RATIO_64.
   245         // other small integers.  We may as well use SILVER_RATIO_64.
   246 	//
   246         //
   247 	// The seed is hashed by mixMurmur64 to produce the `a` parameter.
   247         // The seed is hashed by mixMurmur64 to produce the `a` parameter.
   248 	// The seed is hashed by mixStafford13 to produce the initial `x0`,
   248         // The seed is hashed by mixStafford13 to produce the initial `x0`,
   249 	// which will then be used to produce the first generated value.
   249         // which will then be used to produce the first generated value.
   250 	// The other x values are filled in as if by a SplitMix PRNG with
   250         // The other x values are filled in as if by a SplitMix PRNG with
   251 	// GOLDEN_RATIO_64 as the gamma value and Stafford13 as the mixer.
   251         // GOLDEN_RATIO_64 as the gamma value and Stafford13 as the mixer.
   252         this(RngSupport.mixMurmur64(seed ^= RngSupport.SILVER_RATIO_64),
   252         this(RNGSupport.mixMurmur64(seed ^= RNGSupport.SILVER_RATIO_64),
   253 	     1,
   253              1,
   254 	     RngSupport.mixStafford13(seed),
   254              RNGSupport.mixStafford13(seed),
   255 	     RngSupport.mixStafford13(seed += RngSupport.GOLDEN_RATIO_64),
   255              RNGSupport.mixStafford13(seed += RNGSupport.GOLDEN_RATIO_64),
   256 	     RngSupport.mixStafford13(seed += RngSupport.GOLDEN_RATIO_64),
   256              RNGSupport.mixStafford13(seed += RNGSupport.GOLDEN_RATIO_64),
   257 	     RngSupport.mixStafford13(seed + RngSupport.GOLDEN_RATIO_64));
   257              RNGSupport.mixStafford13(seed + RNGSupport.GOLDEN_RATIO_64));
   258     }
   258     }
   259 
   259 
   260     /**
   260     /**
   261      * Creates a new instance of {@code L64X256Random} that is likely to
   261      * Creates a new instance of {@link L64X256Random} that is likely to
   262      * generate sequences of values that are statistically independent
   262      * generate sequences of values that are statistically independent
   263      * of those of any other instances in the current program execution,
   263      * of those of any other instances in the current program execution,
   264      * but may, and typically does, vary across program invocations.
   264      * but may, and typically does, vary across program invocations.
   265      */
   265      */
   266     public L64X256Random() {
   266     public L64X256Random() {
   267 	// Using GOLDEN_RATIO_64 here gives us a good Weyl sequence of values.
   267         // Using GOLDEN_RATIO_64 here gives us a good Weyl sequence of values.
   268         this(defaultGen.getAndAdd(RngSupport.GOLDEN_RATIO_64));
   268         this(defaultGen.getAndAdd(RNGSupport.GOLDEN_RATIO_64));
   269     }
   269     }
   270 
   270 
   271     /**
   271     /**
   272      * Creates a new instance of {@code L64X256Random} using the specified array of
   272      * Creates a new instance of {@link L64X256Random} using the specified array of
   273      * initial seed bytes. Instances of {@code L64X256Random} created with the same
   273      * initial seed bytes. Instances of {@link L64X256Random} created with the same
   274      * seed array in the same program execution generate identical sequences of values.
   274      * seed array in the same program execution generate identical sequences of values.
   275      *
   275      *
   276      * @param seed the initial seed
   276      * @param seed the initial seed
   277      */
   277      */
   278     public L64X256Random(byte[] seed) {
   278     public L64X256Random(byte[] seed) {
   279 	// Convert the seed to 6 long values, of which the last 4 are not all zero.
   279         // Convert the seed to 6 long values, of which the last 4 are not all zero.
   280 	long[] data = RngSupport.convertSeedBytesToLongs(seed, 6, 4);
   280         long[] data = RNGSupport.convertSeedBytesToLongs(seed, 6, 4);
   281 	long a = data[0], s = data[1], x0 = data[2], x1 = data[3], x2 = data[4], x3 = data[5];
   281         long a = data[0], s = data[1], x0 = data[2], x1 = data[3], x2 = data[4], x3 = data[5];
   282 	// Force a to be odd.
   282         // Force a to be odd.
   283         this.a = a | 1;
   283         this.a = a | 1;
   284         this.s = s;
   284         this.s = s;
   285         this.x0 = x0;
   285         this.x0 = x0;
   286         this.x1 = x1;
   286         this.x1 = x1;
   287         this.x2 = x2;
   287         this.x2 = x2;
   289     }
   289     }
   290 
   290 
   291     /* ---------------- public methods ---------------- */
   291     /* ---------------- public methods ---------------- */
   292 
   292 
   293     /**
   293     /**
   294      * Constructs and returns a new instance of {@code L64X256Random}
   294      * Constructs and returns a new instance of {@link L64X256Random}
   295      * that shares no mutable state with this instance.
   295      * that shares no mutable state with this instance.
   296      * However, with very high probability, the set of values collectively
   296      * However, with very high probability, the set of values collectively
   297      * generated by the two objects has the same statistical properties as if
   297      * generated by the two objects has the same statistical properties as if
   298      * same the quantity of values were generated by a single thread using
   298      * same the quantity of values were generated by a single thread using
   299      * a single {@code L64X256Random} object.  Either or both of the two
   299      * a single {@link L64X256Random} object.  Either or both of the two
   300      * objects may be further split using the {@code split} method,
   300      * objects may be further split using the {@code split} method,
   301      * and the same expected statistical properties apply to the
   301      * and the same expected statistical properties apply to the
   302      * entire set of generators constructed by such recursive splitting.
   302      * entire set of generators constructed by such recursive splitting.
   303      *
   303      *
   304      * @param source a {@code SplittableRng} instance to be used instead
   304      * @param source a {@link SplittableRNG} instance to be used instead
   305      *               of this one as a source of pseudorandom bits used to
   305      *               of this one as a source of pseudorandom bits used to
   306      *               initialize the state of the new ones.
   306      *               initialize the state of the new ones.
   307      * @return a new instance of {@code L64X256Random}
   307      *
   308      */
   308      * @return a new instance of {@link L64X256Random}
   309     public L64X256Random split(SplittableRng source) {
   309      */
   310 	// Literally pick a new instance "at random".
   310     public L64X256Random split(SplittableRNG source) {
   311         return new L64X256Random(source.nextLong(), source.nextLong(), 
   311         // Literally pick a new instance "at random".
   312 				 source.nextLong(), source.nextLong(),
   312         return new L64X256Random(source.nextLong(), source.nextLong(),
   313 				 source.nextLong(), source.nextLong());
   313                                  source.nextLong(), source.nextLong(),
       
   314                                  source.nextLong(), source.nextLong());
   314     }
   315     }
   315 
   316 
   316     /**
   317     /**
   317      * Returns a pseudorandom {@code long} value.
   318      * Returns a pseudorandom {@code long} value.
   318      *
   319      *
   319      * @return a pseudorandom {@code long} value
   320      * @return a pseudorandom {@code long} value
   320      */
   321      */
   321 
       
   322     public long nextLong() {
   322     public long nextLong() {
   323 	final long z = s + x0;
   323         final long z = s + x0;
   324 	s = m * s + a;  // LCG
   324         s = M * s + a;  // LCG
   325 	long q0 = x0, q1 = x1, q2 = x2, q3 = x3;	
   325         long q0 = x0, q1 = x1, q2 = x2, q3 = x3;
   326 	{ long t = q1 << 17; q2 ^= q0; q3 ^= q1; q1 ^= q2; q0 ^= q3; q2 ^= t; q3 = Long.rotateLeft(q3, 45); }  // xoshiro256 1.0
   326         { long t = q1 << 17; q2 ^= q0; q3 ^= q1; q1 ^= q2; q0 ^= q3; q2 ^= t; q3 = Long.rotateLeft(q3, 45); }  // xoshiro256 1.0
   327 	x0 = q0; x1 = q1; x2 = q2; x3 = q3;
   327         x0 = q0; x1 = q1; x2 = q2; x3 = q3;
   328 	return z;
   328         return z;
   329     }
   329     }
   330 
   330 
   331     public BigInteger period() { return thePeriod; }
   331     public BigInteger period() {
       
   332         return PERIOD;
       
   333     }
   332 }
   334 }