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.1 by dl, Wed Jul 10 15:40:19 2013 UTC vs.
Revision 1.21 by dl, Thu Sep 19 23:19:43 2013 UTC

# Line 25 | Line 25
25  
26   package java.util;
27  
28 + import java.security.SecureRandom;
29 + import java.net.NetworkInterface;
30 + import java.util.Enumeration;
31   import java.util.concurrent.atomic.AtomicLong;
29 import java.util.Spliterator;
32   import java.util.function.IntConsumer;
33   import java.util.function.LongConsumer;
34   import java.util.function.DoubleConsumer;
# Line 35 | Line 37 | import java.util.stream.IntStream;
37   import java.util.stream.LongStream;
38   import java.util.stream.DoubleStream;
39  
38
40   /**
41   * A generator of uniform pseudorandom values applicable for use in
42   * (among other contexts) isolated parallel computations that may
43 < * generate subtasks. Class SplittableRandom supports methods for
44 < * producing pseudorandom nunmbers of type {@code int}, {@code long},
43 > * generate subtasks. Class {@code SplittableRandom} supports methods for
44 > * producing pseudorandom numbers of type {@code int}, {@code long},
45   * and {@code double} with similar usages as for class
46 < * {@link java.util.Random} but differs in the following ways: <ul>
46 > * {@link java.util.Random} but differs in the following ways:
47 > *
48 > * <ul>
49   *
50   * <li>Series of generated values pass the DieHarder suite testing
51   * independence and uniformity properties of random number generators.
# Line 50 | Line 53 | import java.util.stream.DoubleStream;
53   * href="http://www.phy.duke.edu/~rgb/General/dieharder.php"> version
54   * 3.31.1</a>.) These tests validate only the methods for certain
55   * types and ranges, but similar properties are expected to hold, at
56 < * least approximately, for others as well.  </li>
56 > * least approximately, for others as well. The <em>period</em>
57 > * (length of any series of generated values before it repeats) is at
58 > * least 2<sup>64</sup>. </li>
59   *
60   * <li> Method {@link #split} constructs and returns a new
61   * SplittableRandom instance that shares no mutable state with the
62 < * current instance. However, with very high probability, the set of
63 < * values collectively generated by the two objects has the same
62 > * current instance. However, with very high probability, the
63 > * values collectively generated by the two objects have the same
64   * statistical properties as if the same quantity of values were
65   * generated by a single thread using a single {@code
66   * SplittableRandom} object.  </li>
# Line 73 | Line 78 | import java.util.stream.DoubleStream;
78   *
79   * </ul>
80   *
81 + * <p>Instances of {@code SplittableRandom} are not cryptographically
82 + * secure.  Consider instead using {@link java.security.SecureRandom}
83 + * in security-sensitive applications. Additionally,
84 + * default-constructed instances do not use a cryptographically random
85 + * seed unless the {@linkplain System#getProperty system property}
86 + * {@code java.util.secureRandomSeed} is set to {@code true}.
87 + *
88   * @author  Guy Steele
89 + * @author  Doug Lea
90   * @since   1.8
91   */
92   public class SplittableRandom {
93  
94      /*
82     * File organization: First the non-public methods that constitute
83     * the main algorithm, then the main public methods, followed by
84     * some custom spliterator classes needed for stream methods.
85     *
86     * Credits: Primary algorithm and code by Guy Steele.  Stream
87     * support methods by Doug Lea.  Documentation jointly produced
88     * with additional help from Brian Goetz.
89     */
90
91    /*
95       * Implementation Overview.
96       *
97       * This algorithm was inspired by the "DotMix" algorithm by
98       * Leiserson, Schardl, and Sukha "Deterministic Parallel
99       * Random-Number Generation for Dynamic-Multithreading Platforms",
100 <     * PPoPP 2012, but improves and extends it in several ways.
100 >     * PPoPP 2012, as well as those in "Parallel random numbers: as
101 >     * easy as 1, 2, 3" by Salmon, Morae, Dror, and Shaw, SC 2011.  It
102 >     * differs mainly in simplifying and cheapening operations.
103 >     *
104 >     * The primary update step (method nextSeed()) is to add a
105 >     * constant ("gamma") to the current (64 bit) seed, forming a
106 >     * simple sequence.  The seed and the gamma values for any two
107 >     * SplittableRandom instances are highly likely to be different.
108 >     *
109 >     * Methods nextLong, nextInt, and derivatives do not return the
110 >     * sequence (seed) values, but instead a hash-like bit-mix of
111 >     * their bits, producing more independently distributed sequences.
112 >     * For nextLong, the mix64 function is based on David Stafford's
113 >     * (http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html)
114 >     * "Mix13" variant of the "64-bit finalizer" function in Austin
115 >     * Appleby's MurmurHash3 algorithm See
116 >     * http://code.google.com/p/smhasher/wiki/MurmurHash3 . The mix32
117 >     * function is based on Stafford's Mix04 mix function, but returns
118 >     * the upper 32 bits cast as int.
119 >     *
120 >     * The split operation uses the current generator to form the seed
121 >     * and gamma for another SplittableRandom.  To conservatively
122 >     * avoid potential correlations between seed and value generation,
123 >     * gamma selection (method mixGamma) uses different
124 >     * (Murmurhash3's) mix constants.  To avoid potential weaknesses
125 >     * in bit-mixing transformations, we restrict gammas to odd values
126 >     * with at least 24 0-1 or 1-0 bit transitions.  Rather than
127 >     * rejecting candidates with too few or too many bits set, method
128 >     * mixGamma flips some bits (which has the effect of mapping at
129 >     * most 4 to any given gamma value).  This reduces the effective
130 >     * set of 64bit odd gamma values by about 2%, and serves as an
131 >     * automated screening for sequence constant selection that is
132 >     * left as an empirical decision in some other hashing and crypto
133 >     * algorithms.
134 >     *
135 >     * The resulting generator thus transforms a sequence in which
136 >     * (typically) many bits change on each step, with an inexpensive
137 >     * mixer with good (but less than cryptographically secure)
138 >     * avalanching.
139 >     *
140 >     * The default (no-argument) constructor, in essence, invokes
141 >     * split() for a common "defaultGen" SplittableRandom.  Unlike
142 >     * other cases, this split must be performed in a thread-safe
143 >     * manner, so we use an AtomicLong to represent the seed rather
144 >     * than use an explicit SplittableRandom. To bootstrap the
145 >     * defaultGen, we start off using a seed based on current time and
146 >     * network interface address unless the java.util.secureRandomSeed
147 >     * property is set. This serves as a slimmed-down (and insecure)
148 >     * variant of SecureRandom that also avoids stalls that may occur
149 >     * when using /dev/random.
150 >     *
151 >     * It is a relatively simple matter to apply the basic design here
152 >     * to use 128 bit seeds. However, emulating 128bit arithmetic and
153 >     * carrying around twice the state add more overhead than appears
154 >     * warranted for current usages.
155       *
156 <     * The primary update step is simply to add a constant ("gamma")
157 <     * to the current seed, modulo a prime ("George"). However, the
158 <     * nextLong and nextInt methods do not return this value, but
159 <     * instead the results of bit-mixing transformations that produce
103 <     * more uniformly distributed sequences.
104 <     *
105 <     * "George" is the otherwise nameless (because it cannot be
106 <     * represented) prime number 2^64+13. Using a prime number larger
107 <     * than can fit in a long ensures that all possible long values
108 <     * can occur, plus 13 others that just get skipped over when they
109 <     * are encountered; see method addGammaModGeorge. For this to
110 <     * work, initial gamma values must be at least 13.
111 <     *
112 <     * The value of gamma differs for each instance across a series of
113 <     * splits, and is generated using a slightly stripped-down variant
114 <     * of the same algorithm, but operating across calls to split(),
115 <     * not calls to nextLong(): Each instance carries the state of
116 <     * this generator as nextSplit, and uses mix64(nextSplit) as its
117 <     * own gamma value. Computations of gammas themselves use a fixed
118 <     * constant as the second argument to the addGammaModGeorge
119 <     * function, GAMMA_GAMMA, a "genuinely random" number from a
120 <     * radioactive decay reading (obtained from
121 <     * http://www.fourmilab.ch/hotbits/) meeting the above range
122 <     * constraint. Using a fixed constant maintains the invariant that
123 <     * the value of gamma is the same for every instance that is at
124 <     * the same split-distance from their common root. (Note: there is
125 <     * nothing especially magic about obtaining this constant from a
126 <     * "truly random" physical source rather than just choosing one
127 <     * arbitrarily; using "hotbits" was merely an aesthetically pleasing
128 <     * choice.  In either case, good statistical behavior of the
129 <     * algorithm should be, and was, verified by using the DieHarder
130 <     * test suite.)
131 <     *
132 <     * The mix64 bit-mixing function called by nextLong and other
133 <     * methods computes the same value as the "64-bit finalizer"
134 <     * function in Austin Appleby's MurmurHash3 algorithm.  See
135 <     * http://code.google.com/p/smhasher/wiki/MurmurHash3 , which
136 <     * comments: "The constants for the finalizers were generated by a
137 <     * simple simulated-annealing algorithm, and both avalanche all
138 <     * bits of 'h' to within 0.25% bias." It also appears to work to
139 <     * use instead any of the variants proposed by David Stafford at
140 <     * http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html
141 <     * but these variants have not yet been tested as thoroughly
142 <     * in the context of the implementation of SplittableRandom.
143 <     *
144 <     * The mix32 function used for nextInt just consists of two of the
145 <     * five lines of mix64; avalanche testing shows that the 64-bit result
146 <     * has its top 32 bits avalanched well, though not the bottom 32 bits.
147 <     * DieHarder tests show that it is adequate for generating one
148 <     * random int from the 64-bit result of nextSeed.
149 <     *
150 <     * Support for the default (no-argument) constructor relies on an
151 <     * AtomicLong (defaultSeedGenerator) to help perform the
152 <     * equivalent of a split of a statically constructed
153 <     * SplittableRandom. Unlike other cases, this split must be
154 <     * performed in a thread-safe manner. We use
155 <     * AtomicLong.compareAndSet as the (typically) most efficient
156 <     * mechanism. To bootstrap, we start off using System.nanotime(),
157 <     * and update using another "genuinely random" constant
158 <     * DEFAULT_SEED_GAMMA. The default constructor uses GAMMA_GAMMA,
159 <     * not 0, for its splitSeed argument (addGammaModGeorge(0,
160 <     * GAMMA_GAMMA) == GAMMA_GAMMA) to reflect that each is split from
161 <     * this root generator, even though the root is not explicitly
162 <     * represented as a SplittableRandom.
163 <     */
164 <
165 <    /**
166 <     * The "genuinely random" value for producing new gamma values.
167 <     * The value is arbitrary, subject to the requirement that it be
168 <     * greater or equal to 13.
169 <     */
170 <    private static final long GAMMA_GAMMA = 0xF2281E2DBA6606F3L;
171 <
172 <    /**
173 <     * The "genuinely random" seed update value for default constructors.
174 <     * The value is arbitrary, subject to the requirement that it be
175 <     * greater or equal to 13.
176 <     */
177 <    private static final long DEFAULT_SEED_GAMMA = 0xBD24B73A95FB84D9L;
156 >     * File organization: First the non-public methods that constitute
157 >     * the main algorithm, then the main public methods, followed by
158 >     * some custom spliterator classes needed for stream methods.
159 >     */
160  
161      /**
162 <     * The next seed for default constructors.
162 >     * The golden ratio scaled to 64bits, used as the initial gamma
163 >     * value for (unsplit) SplittableRandoms.
164       */
165 <    private static final AtomicLong defaultSeedGenerator =
183 <        new AtomicLong(System.nanoTime());
165 >    private static final long GOLDEN_GAMMA = 0x9e3779b97f4a7c15L;
166  
167      /**
168 <     * The seed, updated only via method nextSeed.
168 >     * The least non-zero value returned by nextDouble(). This value
169 >     * is scaled by a random value of 53 bits to produce a result.
170       */
171 <    private long seed;
171 >    private static final double DOUBLE_ULP = 1.0 / (1L << 53);
172  
173      /**
174 <     * The constant value added to seed (mod George) on each update.
174 >     * The seed. Updated only via method nextSeed.
175       */
176 <    private final long gamma;
176 >    private long seed;
177  
178      /**
179 <     * The next seed to use for splits. Propagated using
197 <     * addGammaModGeorge across instances.
179 >     * The step value.
180       */
181 <    private final long nextSplit;
181 >    private final long gamma;
182  
183      /**
184 <     * Internal constructor used by all other constructors and by
203 <     * method split. Establishes the initial seed for this instance,
204 <     * and uses the given splitSeed to establish gamma, as well as the
205 <     * nextSplit to use by this instance.
184 >     * Internal constructor used by all others except default constructor.
185       */
186 <    private SplittableRandom(long seed, long splitSeed) {
186 >    private SplittableRandom(long seed, long gamma) {
187          this.seed = seed;
188 <        long s = splitSeed, g;
210 <        do { // ensure gamma >= 13, considered as an unsigned integer
211 <            s = addGammaModGeorge(s, GAMMA_GAMMA);
212 <            g = mix64(s);
213 <        } while (Long.compareUnsigned(g, 13L) < 0);
214 <        this.gamma = g;
215 <        this.nextSplit = s;
188 >        this.gamma = gamma;
189      }
190  
191      /**
192 <     * Adds the given gamma value, g, to the given seed value s, mod
193 <     * George (2^64+13). We regard s and g as unsigned values
194 <     * (ranging from 0 to 2^64-1). We add g to s either once or twice
195 <     * (mod George) as necessary to produce an (unsigned) result less
196 <     * than 2^64.  We require that g must be at least 13. This
197 <     * guarantees that if (s+g) mod George >= 2^64 then (s+g+g) mod
198 <     * George < 2^64; thus we need only a conditional, not a loop,
199 <     * to be sure of getting a representable value.
200 <     *
201 <     * @param s a seed value
202 <     * @param g a gamma value, 13 <= g (as unsigned)
203 <     */
231 <    private static long addGammaModGeorge(long s, long g) {
232 <        long p = s + g;
233 <        if (Long.compareUnsigned(p, g) >= 0)
234 <            return p;
235 <        long q = p - 13L;
236 <        return (Long.compareUnsigned(p, 13L) >= 0) ? q : (q + g);
192 >     * Computes Stafford variant 13 of 64bit mix function.
193 >     */
194 >    private static long mix64(long z) {
195 >        z *= 0xbf58476d1ce4e5b9L;
196 >        z = (z ^ (z >>> 32)) * 0x94d049bb133111ebL;
197 >        return z ^ (z >>> 32);
198 >    }
199 >
200 >    private static long xmix64(long z) {
201 >        z *= 0xbf58476d1ce4e5b9L;
202 >        z = (z ^ (z >>> 27)) * 0x94d049bb133111ebL;
203 >        return z ^ (z >>> 31);
204      }
205  
206      /**
207 <     * Updates in-place and returns seed.
241 <     * See above for explanation.
207 >     * Returns the 32 high bits of Stafford variant 4 mix64 function as int.
208       */
209 <    private long nextSeed() {
210 <        return seed = addGammaModGeorge(seed, gamma);
209 >    private static int mix32(long z) {
210 >        z *= 0x62a9d9ed799705f5L;
211 >        return (int)(((z ^ (z >>> 28)) * 0xcb24d0a5c88c35b3L) >>> 32);
212      }
213  
214      /**
215 <     * Returns a bit-mixed transformation of its argument.
249 <     * See above for explanation.
215 >     * Returns the gamma value to use for a new split instance.
216       */
217 <    private static long mix64(long z) {
218 <        z ^= (z >>> 33);
219 <        z *= 0xff51afd7ed558ccdL;
220 <        z ^= (z >>> 33);
221 <        z *= 0xc4ceb9fe1a85ec53L;
222 <        z ^= (z >>> 33);
257 <        return z;
217 >    private static long mixGamma(long z) {
218 >        z *= 0xff51afd7ed558ccdL;                   // MurmurHash3 mix constants
219 >        z = (z ^ (z >>> 33)) * 0xc4ceb9fe1a85ec53L;
220 >        z = (z ^ (z >>> 33)) | 1L;                  // force to be odd
221 >        int n = Long.bitCount(z ^ (z >>> 1));       // ensure enough transitions
222 >        return (n < 24) ? z ^ 0xaaaaaaaaaaaaaaaaL : z;
223      }
224  
225      /**
226 <     * Returns a bit-mixed int transformation of its argument.
262 <     * See above for explanation.
226 >     * Adds gamma to seed.
227       */
228 <    private static int mix32(long z) {
229 <        z ^= (z >>> 33);
266 <        z *= 0xc4ceb9fe1a85ec53L;
267 <        return (int)(z >>> 32);
228 >    private long nextSeed() {
229 >        return seed += gamma;
230      }
231  
232      /**
233 <     * Atomically updates and returns next seed for default constructor
233 >     * The seed generator for default constructors.
234       */
235 <    private static long nextDefaultSeed() {
236 <        long oldSeed, newSeed;
237 <        do {
238 <            oldSeed = defaultSeedGenerator.get();
239 <            newSeed = addGammaModGeorge(oldSeed, DEFAULT_SEED_GAMMA);
240 <        } while (!defaultSeedGenerator.compareAndSet(oldSeed, newSeed));
241 <        return mix64(newSeed);
235 >    private static final AtomicLong defaultGen = new AtomicLong(initialSeed());
236 >
237 >    private static long initialSeed() {
238 >        String pp = java.security.AccessController.doPrivileged(
239 >                new sun.security.action.GetPropertyAction(
240 >                        "java.util.secureRandomSeed"));
241 >        if (pp != null && pp.equalsIgnoreCase("true")) {
242 >            byte[] seedBytes = java.security.SecureRandom.getSeed(8);
243 >            long s = (long)(seedBytes[0]) & 0xffL;
244 >            for (int i = 1; i < 8; ++i)
245 >                s = (s << 8) | ((long)(seedBytes[i]) & 0xffL);
246 >            return s;
247 >        }
248 >        long h = 0L;
249 >        try {
250 >            Enumeration<NetworkInterface> ifcs =
251 >                NetworkInterface.getNetworkInterfaces();
252 >            boolean retry = false; // retry once if getHardwareAddress is null
253 >            while (ifcs.hasMoreElements()) {
254 >                NetworkInterface ifc = ifcs.nextElement();
255 >                if (!ifc.isVirtual()) { // skip fake addresses
256 >                    byte[] bs = ifc.getHardwareAddress();
257 >                    if (bs != null) {
258 >                        int n = bs.length;
259 >                        int m = Math.min(n >>> 1, 4);
260 >                        for (int i = 0; i < m; ++i)
261 >                            h = (h << 16) ^ (bs[i] << 8) ^ bs[n-1-i];
262 >                        if (m < 4)
263 >                            h = (h << 8) ^ bs[n-1-m];
264 >                        h = mix64(h);
265 >                        break;
266 >                    }
267 >                    else if (!retry)
268 >                        retry = true;
269 >                    else
270 >                        break;
271 >                }
272 >            }
273 >        } catch (Exception ignore) {
274 >        }
275 >        return (h ^ mix64(System.currentTimeMillis()) ^
276 >                mix64(System.nanoTime()));
277      }
278  
279 +    // IllegalArgumentException messages
280 +    static final String BadBound = "bound must be positive";
281 +    static final String BadRange = "bound must be greater than origin";
282 +    static final String BadSize  = "size must be non-negative";
283 +
284      /*
285       * Internal versions of nextX methods used by streams, as well as
286       * the public nextX(origin, bound) methods.  These exist mainly to
# Line 310 | Line 312 | public class SplittableRandom {
312           * evenly divisible by the range. The loop rejects candidates
313           * computed from otherwise over-represented values.  The
314           * expected number of iterations under an ideal generator
315 <         * varies from 1 to 2, depending on the bound.
315 >         * varies from 1 to 2, depending on the bound. The loop itself
316 >         * takes an unlovable form. Because the first candidate is
317 >         * already available, we need a break-in-the-middle
318 >         * construction, which is concisely but cryptically performed
319 >         * within the while-condition of a body-less for loop.
320           *
321           * 4. Otherwise, the range cannot be represented as a positive
322 <         * long.  Repeatedly generate unbounded longs until obtaining
323 <         * a candidate meeting constraints (with an expected number of
324 <         * iterations of less than two).
322 >         * long.  The loop repeatedly generates unbounded longs until
323 >         * obtaining a candidate meeting constraints (with an expected
324 >         * number of iterations of less than two).
325           */
326  
327          long r = mix64(nextSeed());
328          if (origin < bound) {
329              long n = bound - origin, m = n - 1;
330 <            if ((n & m) == 0L) // power of two
330 >            if ((n & m) == 0L)  // power of two
331                  r = (r & m) + origin;
332 <            else if (n > 0) { // reject over-represented candidates
332 >            else if (n > 0L) {  // reject over-represented candidates
333                  for (long u = r >>> 1;            // ensure nonnegative
334 <                     u + m - (r = u % n) < 0L;    // reject
334 >                     u + m - (r = u % n) < 0L;    // rejection check
335                       u = mix64(nextSeed()) >>> 1) // retry
336                      ;
337                  r += origin;
338              }
339 <            else {             // range not representable as long
339 >            else {              // range not representable as long
340                  while (r < origin || r >= bound)
341                      r = mix64(nextSeed());
342              }
# Line 350 | Line 356 | public class SplittableRandom {
356          int r = mix32(nextSeed());
357          if (origin < bound) {
358              int n = bound - origin, m = n - 1;
359 <            if ((n & m) == 0L)
359 >            if ((n & m) == 0)
360                  r = (r & m) + origin;
361              else if (n > 0) {
362                  for (int u = r >>> 1;
363 <                     u + m - (r = u % n) < 0L;
363 >                     u + m - (r = u % n) < 0;
364                       u = mix32(nextSeed()) >>> 1)
365                      ;
366                  r += origin;
# Line 375 | Line 381 | public class SplittableRandom {
381       * @return a pseudorandom value
382       */
383      final double internalNextDouble(double origin, double bound) {
384 <        long bits = (1023L << 52) | (nextLong() >>> 12);
379 <        double r = Double.longBitsToDouble(bits) - 1.0;
384 >        double r = (nextLong() >>> 11) * DOUBLE_ULP;
385          if (origin < bound) {
386              r = r * (bound - origin) + origin;
387 <            if (r == bound) // correct for rounding
387 >            if (r >= bound) // correct for rounding
388                  r = Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
389          }
390          return r;
# Line 388 | Line 393 | public class SplittableRandom {
393      /* ---------------- public methods ---------------- */
394  
395      /**
396 <     * Creates a new SplittableRandom instance using the given initial
397 <     * seed. Two SplittableRandom instances created with the same seed
398 <     * generate identical sequences of values.
396 >     * Creates a new SplittableRandom instance using the specified
397 >     * initial seed. SplittableRandom instances created with the same
398 >     * seed in the same program generate identical sequences of values.
399       *
400       * @param seed the initial seed
401       */
402      public SplittableRandom(long seed) {
403 <        this(seed, 0);
403 >        this(seed, GOLDEN_GAMMA);
404      }
405  
406      /**
# Line 404 | Line 409 | public class SplittableRandom {
409       * of those of any other instances in the current program; and
410       * may, and typically does, vary across program invocations.
411       */
412 <    public SplittableRandom() {
413 <        this(nextDefaultSeed(), GAMMA_GAMMA);
412 >    public SplittableRandom() { // emulate defaultGen.split()
413 >        long s = defaultGen.getAndAdd(2*GOLDEN_GAMMA);
414 >        this.seed = mix64(s);
415 >        this.gamma = mixGamma(s + GOLDEN_GAMMA);
416      }
417  
418      /**
# Line 423 | Line 430 | public class SplittableRandom {
430       * @return the new SplittableRandom instance
431       */
432      public SplittableRandom split() {
433 <        return new SplittableRandom(nextSeed(), nextSplit);
433 >        return new SplittableRandom(nextLong(), mixGamma(nextSeed()));
434      }
435  
436      /**
437       * Returns a pseudorandom {@code int} value.
438       *
439 <     * @return a pseudorandom value
439 >     * @return a pseudorandom {@code int} value
440       */
441      public int nextInt() {
442          return mix32(nextSeed());
443      }
444  
445      /**
446 <     * Returns a pseudorandom {@code int} value between 0 (inclusive)
446 >     * Returns a pseudorandom {@code int} value between zero (inclusive)
447       * and the specified bound (exclusive).
448       *
449 <     * @param bound the bound on the random number to be returned.  Must be
450 <     *        positive.
451 <     * @return a pseudorandom {@code int} value between {@code 0}
452 <     *         (inclusive) and the bound (exclusive).
446 <     * @exception IllegalArgumentException if the bound is not positive
449 >     * @param bound the upper bound (exclusive).  Must be positive.
450 >     * @return a pseudorandom {@code int} value between zero
451 >     *         (inclusive) and the bound (exclusive)
452 >     * @throws IllegalArgumentException if {@code bound} is not positive
453       */
454      public int nextInt(int bound) {
455          if (bound <= 0)
456 <            throw new IllegalArgumentException("bound must be positive");
456 >            throw new IllegalArgumentException(BadBound);
457          // Specialize internalNextInt for origin 0
458          int r = mix32(nextSeed());
459          int m = bound - 1;
460 <        if ((bound & m) == 0L) // power of two
460 >        if ((bound & m) == 0) // power of two
461              r &= m;
462          else { // reject over-represented candidates
463              for (int u = r >>> 1;
464 <                 u + m - (r = u % bound) < 0L;
464 >                 u + m - (r = u % bound) < 0;
465                   u = mix32(nextSeed()) >>> 1)
466                  ;
467          }
# Line 469 | Line 475 | public class SplittableRandom {
475       * @param origin the least value returned
476       * @param bound the upper bound (exclusive)
477       * @return a pseudorandom {@code int} value between the origin
478 <     *         (inclusive) and the bound (exclusive).
479 <     * @exception IllegalArgumentException if {@code origin} is greater than
478 >     *         (inclusive) and the bound (exclusive)
479 >     * @throws IllegalArgumentException if {@code origin} is greater than
480       *         or equal to {@code bound}
481       */
482      public int nextInt(int origin, int bound) {
483          if (origin >= bound)
484 <            throw new IllegalArgumentException("bound must be greater than origin");
484 >            throw new IllegalArgumentException(BadRange);
485          return internalNextInt(origin, bound);
486      }
487  
488      /**
489       * Returns a pseudorandom {@code long} value.
490       *
491 <     * @return a pseudorandom value
491 >     * @return a pseudorandom {@code long} value
492       */
493      public long nextLong() {
494          return mix64(nextSeed());
495      }
496  
497      /**
498 <     * Returns a pseudorandom {@code long} value between 0 (inclusive)
498 >     * Returns a pseudorandom {@code long} value between zero (inclusive)
499       * and the specified bound (exclusive).
500       *
501 <     * @param bound the bound on the random number to be returned.  Must be
502 <     *        positive.
503 <     * @return a pseudorandom {@code long} value between {@code 0}
504 <     *         (inclusive) and the bound (exclusive).
499 <     * @exception IllegalArgumentException if the bound is not positive
501 >     * @param bound the upper bound (exclusive).  Must be positive.
502 >     * @return a pseudorandom {@code long} value between zero
503 >     *         (inclusive) and the bound (exclusive)
504 >     * @throws IllegalArgumentException if {@code bound} is not positive
505       */
506      public long nextLong(long bound) {
507          if (bound <= 0)
508 <            throw new IllegalArgumentException("bound must be positive");
508 >            throw new IllegalArgumentException(BadBound);
509          // Specialize internalNextLong for origin 0
510          long r = mix64(nextSeed());
511          long m = bound - 1;
# Line 522 | Line 527 | public class SplittableRandom {
527       * @param origin the least value returned
528       * @param bound the upper bound (exclusive)
529       * @return a pseudorandom {@code long} value between the origin
530 <     *         (inclusive) and the bound (exclusive).
531 <     * @exception IllegalArgumentException if {@code origin} is greater than
530 >     *         (inclusive) and the bound (exclusive)
531 >     * @throws IllegalArgumentException if {@code origin} is greater than
532       *         or equal to {@code bound}
533       */
534      public long nextLong(long origin, long bound) {
535          if (origin >= bound)
536 <            throw new IllegalArgumentException("bound must be greater than origin");
536 >            throw new IllegalArgumentException(BadRange);
537          return internalNextLong(origin, bound);
538      }
539  
540      /**
541 <     * Returns a pseudorandom {@code double} value between {@code 0.0}
542 <     * (inclusive) and {@code 1.0} (exclusive).
541 >     * Returns a pseudorandom {@code double} value between zero
542 >     * (inclusive) and one (exclusive).
543       *
544 <     * @return a pseudorandom value between {@code 0.0}
545 <     * (inclusive) and {@code 1.0} (exclusive)
544 >     * @return a pseudorandom {@code double} value between zero
545 >     *         (inclusive) and one (exclusive)
546       */
547      public double nextDouble() {
548 <        long bits = (1023L << 52) | (nextLong() >>> 12);
544 <        return Double.longBitsToDouble(bits) - 1.0;
548 >        return (mix64(nextSeed()) >>> 11) * DOUBLE_ULP;
549      }
550  
551      /**
552       * Returns a pseudorandom {@code double} value between 0.0
553       * (inclusive) and the specified bound (exclusive).
554       *
555 <     * @param bound the bound on the random number to be returned.  Must be
556 <     *        positive.
557 <     * @return a pseudorandom {@code double} value between {@code 0.0}
554 <     *         (inclusive) and the bound (exclusive).
555 >     * @param bound the upper bound (exclusive).  Must be positive.
556 >     * @return a pseudorandom {@code double} value between zero
557 >     *         (inclusive) and the bound (exclusive)
558       * @throws IllegalArgumentException if {@code bound} is not positive
559       */
560      public double nextDouble(double bound) {
561 <        if (bound <= 0.0)
562 <            throw new IllegalArgumentException("bound must be positive");
563 <        double result = nextDouble() * bound;
561 >        if (!(bound > 0.0))
562 >            throw new IllegalArgumentException(BadBound);
563 >        double result = (mix64(nextSeed()) >>> 11) * DOUBLE_ULP * bound;
564          return (result < bound) ?  result : // correct for rounding
565              Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
566      }
567  
568      /**
569 <     * Returns a pseudorandom {@code double} value between the given
569 >     * Returns a pseudorandom {@code double} value between the specified
570       * origin (inclusive) and bound (exclusive).
571       *
572       * @param origin the least value returned
573 <     * @param bound the upper bound
573 >     * @param bound the upper bound (exclusive)
574       * @return a pseudorandom {@code double} value between the origin
575 <     *         (inclusive) and the bound (exclusive).
575 >     *         (inclusive) and the bound (exclusive)
576       * @throws IllegalArgumentException if {@code origin} is greater than
577       *         or equal to {@code bound}
578       */
579      public double nextDouble(double origin, double bound) {
580 <        if (origin >= bound)
581 <            throw new IllegalArgumentException("bound must be greater than origin");
580 >        if (!(origin < bound))
581 >            throw new IllegalArgumentException(BadRange);
582          return internalNextDouble(origin, bound);
583      }
584  
585 +    /**
586 +     * Returns a pseudorandom {@code boolean} value.
587 +     *
588 +     * @return a pseudorandom {@code boolean} value
589 +     */
590 +    public boolean nextBoolean() {
591 +        return mix32(nextSeed()) < 0;
592 +    }
593 +
594      // stream methods, coded in a way intended to better isolate for
595      // maintenance purposes the small differences across forms.
596  
597      /**
598 <     * Returns a stream with the given {@code streamSize} number of
599 <     * pseudorandom {@code int} values.
598 >     * Returns a stream producing the given {@code streamSize} number
599 >     * of pseudorandom {@code int} values from this generator and/or
600 >     * one split from it.
601       *
602       * @param streamSize the number of values to generate
603       * @return a stream of pseudorandom {@code int} values
604       * @throws IllegalArgumentException if {@code streamSize} is
605 <     * less than zero
605 >     *         less than zero
606       */
607      public IntStream ints(long streamSize) {
608          if (streamSize < 0L)
609 <            throw new IllegalArgumentException("negative Stream size");
609 >            throw new IllegalArgumentException(BadSize);
610          return StreamSupport.intStream
611              (new RandomIntsSpliterator
612               (this, 0L, streamSize, Integer.MAX_VALUE, 0),
# Line 602 | Line 615 | public class SplittableRandom {
615  
616      /**
617       * Returns an effectively unlimited stream of pseudorandom {@code int}
618 <     * values
618 >     * values from this generator and/or one split from it.
619       *
620       * @implNote This method is implemented to be equivalent to {@code
621       * ints(Long.MAX_VALUE)}.
# Line 617 | Line 630 | public class SplittableRandom {
630      }
631  
632      /**
633 <     * Returns a stream with the given {@code streamSize} number of
634 <     * pseudorandom {@code int} values, each conforming to the given
635 <     * origin and bound.
633 >     * Returns a stream producing the given {@code streamSize} number
634 >     * of pseudorandom {@code int} values from this generator and/or one split
635 >     * from it; each value conforms to the given origin (inclusive) and bound
636 >     * (exclusive).
637       *
638       * @param streamSize the number of values to generate
639 <     * @param randomNumberOrigin the origin of each random value
640 <     * @param randomNumberBound the bound of each random value
639 >     * @param randomNumberOrigin the origin (inclusive) of each random value
640 >     * @param randomNumberBound the bound (exclusive) of each random value
641       * @return a stream of pseudorandom {@code int} values,
642 <     * each with the given origin and bound.
642 >     *         each with the given origin (inclusive) and bound (exclusive)
643       * @throws IllegalArgumentException if {@code streamSize} is
644 <     * less than zero.
631 <     * @throws IllegalArgumentException if {@code randomNumberOrigin}
644 >     *         less than zero, or {@code randomNumberOrigin}
645       *         is greater than or equal to {@code randomNumberBound}
646       */
647      public IntStream ints(long streamSize, int randomNumberOrigin,
648                            int randomNumberBound) {
649          if (streamSize < 0L)
650 <            throw new IllegalArgumentException("negative Stream size");
650 >            throw new IllegalArgumentException(BadSize);
651          if (randomNumberOrigin >= randomNumberBound)
652 <            throw new IllegalArgumentException("bound must be greater than origin");
652 >            throw new IllegalArgumentException(BadRange);
653          return StreamSupport.intStream
654              (new RandomIntsSpliterator
655               (this, 0L, streamSize, randomNumberOrigin, randomNumberBound),
# Line 645 | Line 658 | public class SplittableRandom {
658  
659      /**
660       * Returns an effectively unlimited stream of pseudorandom {@code
661 <     * int} values, each conforming to the given origin and bound.
661 >     * int} values from this generator and/or one split from it; each value
662 >     * conforms to the given origin (inclusive) and bound (exclusive).
663       *
664       * @implNote This method is implemented to be equivalent to {@code
665       * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
666       *
667 <     * @param randomNumberOrigin the origin of each random value
668 <     * @param randomNumberBound the bound of each random value
667 >     * @param randomNumberOrigin the origin (inclusive) of each random value
668 >     * @param randomNumberBound the bound (exclusive) of each random value
669       * @return a stream of pseudorandom {@code int} values,
670 <     * each with the given origin and bound.
670 >     *         each with the given origin (inclusive) and bound (exclusive)
671       * @throws IllegalArgumentException if {@code randomNumberOrigin}
672       *         is greater than or equal to {@code randomNumberBound}
673       */
674      public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
675          if (randomNumberOrigin >= randomNumberBound)
676 <            throw new IllegalArgumentException("bound must be greater than origin");
676 >            throw new IllegalArgumentException(BadRange);
677          return StreamSupport.intStream
678              (new RandomIntsSpliterator
679               (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
# Line 667 | Line 681 | public class SplittableRandom {
681      }
682  
683      /**
684 <     * Returns a stream with the given {@code streamSize} number of
685 <     * pseudorandom {@code long} values.
684 >     * Returns a stream producing the given {@code streamSize} number
685 >     * of pseudorandom {@code long} values from this generator and/or
686 >     * one split from it.
687       *
688       * @param streamSize the number of values to generate
689 <     * @return a stream of {@code long} values
689 >     * @return a stream of pseudorandom {@code long} values
690       * @throws IllegalArgumentException if {@code streamSize} is
691 <     * less than zero
691 >     *         less than zero
692       */
693      public LongStream longs(long streamSize) {
694          if (streamSize < 0L)
695 <            throw new IllegalArgumentException("negative Stream size");
695 >            throw new IllegalArgumentException(BadSize);
696          return StreamSupport.longStream
697              (new RandomLongsSpliterator
698               (this, 0L, streamSize, Long.MAX_VALUE, 0L),
# Line 685 | Line 700 | public class SplittableRandom {
700      }
701  
702      /**
703 <     * Returns an effectively unlimited stream of pseudorandom {@code long}
704 <     * values.
703 >     * Returns an effectively unlimited stream of pseudorandom {@code
704 >     * long} values from this generator and/or one split from it.
705       *
706       * @implNote This method is implemented to be equivalent to {@code
707       * longs(Long.MAX_VALUE)}.
# Line 701 | Line 716 | public class SplittableRandom {
716      }
717  
718      /**
719 <     * Returns a stream with the given {@code streamSize} number of
720 <     * pseudorandom {@code long} values, each conforming to the
721 <     * given origin and bound.
719 >     * Returns a stream producing the given {@code streamSize} number of
720 >     * pseudorandom {@code long} values from this generator and/or one split
721 >     * from it; each value conforms to the given origin (inclusive) and bound
722 >     * (exclusive).
723       *
724       * @param streamSize the number of values to generate
725 <     * @param randomNumberOrigin the origin of each random value
726 <     * @param randomNumberBound the bound of each random value
725 >     * @param randomNumberOrigin the origin (inclusive) of each random value
726 >     * @param randomNumberBound the bound (exclusive) of each random value
727       * @return a stream of pseudorandom {@code long} values,
728 <     * each with the given origin and bound.
728 >     *         each with the given origin (inclusive) and bound (exclusive)
729       * @throws IllegalArgumentException if {@code streamSize} is
730 <     * less than zero.
715 <     * @throws IllegalArgumentException if {@code randomNumberOrigin}
730 >     *         less than zero, or {@code randomNumberOrigin}
731       *         is greater than or equal to {@code randomNumberBound}
732       */
733      public LongStream longs(long streamSize, long randomNumberOrigin,
734                              long randomNumberBound) {
735          if (streamSize < 0L)
736 <            throw new IllegalArgumentException("negative Stream size");
736 >            throw new IllegalArgumentException(BadSize);
737          if (randomNumberOrigin >= randomNumberBound)
738 <            throw new IllegalArgumentException("bound must be greater than origin");
738 >            throw new IllegalArgumentException(BadRange);
739          return StreamSupport.longStream
740              (new RandomLongsSpliterator
741               (this, 0L, streamSize, randomNumberOrigin, randomNumberBound),
# Line 729 | Line 744 | public class SplittableRandom {
744  
745      /**
746       * Returns an effectively unlimited stream of pseudorandom {@code
747 <     * long} values, each conforming to the given origin and bound.
747 >     * long} values from this generator and/or one split from it; each value
748 >     * conforms to the given origin (inclusive) and bound (exclusive).
749       *
750       * @implNote This method is implemented to be equivalent to {@code
751       * longs(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
752       *
753 <     * @param randomNumberOrigin the origin of each random value
754 <     * @param randomNumberBound the bound of each random value
753 >     * @param randomNumberOrigin the origin (inclusive) of each random value
754 >     * @param randomNumberBound the bound (exclusive) of each random value
755       * @return a stream of pseudorandom {@code long} values,
756 <     * each with the given origin and bound.
756 >     *         each with the given origin (inclusive) and bound (exclusive)
757       * @throws IllegalArgumentException if {@code randomNumberOrigin}
758       *         is greater than or equal to {@code randomNumberBound}
759       */
760      public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
761          if (randomNumberOrigin >= randomNumberBound)
762 <            throw new IllegalArgumentException("bound must be greater than origin");
762 >            throw new IllegalArgumentException(BadRange);
763          return StreamSupport.longStream
764              (new RandomLongsSpliterator
765               (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
# Line 751 | Line 767 | public class SplittableRandom {
767      }
768  
769      /**
770 <     * Returns a stream with the given {@code streamSize} number of
771 <     * pseudorandom {@code double} values.
770 >     * Returns a stream producing the given {@code streamSize} number of
771 >     * pseudorandom {@code double} values from this generator and/or one split
772 >     * from it; each value is between zero (inclusive) and one (exclusive).
773       *
774       * @param streamSize the number of values to generate
775       * @return a stream of {@code double} values
776       * @throws IllegalArgumentException if {@code streamSize} is
777 <     * less than zero
777 >     *         less than zero
778       */
779      public DoubleStream doubles(long streamSize) {
780          if (streamSize < 0L)
781 <            throw new IllegalArgumentException("negative Stream size");
781 >            throw new IllegalArgumentException(BadSize);
782          return StreamSupport.doubleStream
783              (new RandomDoublesSpliterator
784               (this, 0L, streamSize, Double.MAX_VALUE, 0.0),
# Line 770 | Line 787 | public class SplittableRandom {
787  
788      /**
789       * Returns an effectively unlimited stream of pseudorandom {@code
790 <     * double} values.
790 >     * double} values from this generator and/or one split from it; each value
791 >     * is between zero (inclusive) and one (exclusive).
792       *
793       * @implNote This method is implemented to be equivalent to {@code
794       * doubles(Long.MAX_VALUE)}.
# Line 785 | Line 803 | public class SplittableRandom {
803      }
804  
805      /**
806 <     * Returns a stream with the given {@code streamSize} number of
807 <     * pseudorandom {@code double} values, each conforming to the
808 <     * given origin and bound.
806 >     * Returns a stream producing the given {@code streamSize} number of
807 >     * pseudorandom {@code double} values from this generator and/or one split
808 >     * from it; each value conforms to the given origin (inclusive) and bound
809 >     * (exclusive).
810       *
811       * @param streamSize the number of values to generate
812 <     * @param randomNumberOrigin the origin of each random value
813 <     * @param randomNumberBound the bound of each random value
812 >     * @param randomNumberOrigin the origin (inclusive) of each random value
813 >     * @param randomNumberBound the bound (exclusive) of each random value
814       * @return a stream of pseudorandom {@code double} values,
815 <     * each with the given origin and bound.
815 >     *         each with the given origin (inclusive) and bound (exclusive)
816       * @throws IllegalArgumentException if {@code streamSize} is
817 <     * less than zero.
817 >     *         less than zero
818       * @throws IllegalArgumentException if {@code randomNumberOrigin}
819       *         is greater than or equal to {@code randomNumberBound}
820       */
821      public DoubleStream doubles(long streamSize, double randomNumberOrigin,
822                                  double randomNumberBound) {
823          if (streamSize < 0L)
824 <            throw new IllegalArgumentException("negative Stream size");
825 <        if (randomNumberOrigin >= randomNumberBound)
826 <            throw new IllegalArgumentException("bound must be greater than origin");
824 >            throw new IllegalArgumentException(BadSize);
825 >        if (!(randomNumberOrigin < randomNumberBound))
826 >            throw new IllegalArgumentException(BadRange);
827          return StreamSupport.doubleStream
828              (new RandomDoublesSpliterator
829               (this, 0L, streamSize, randomNumberOrigin, randomNumberBound),
# Line 813 | Line 832 | public class SplittableRandom {
832  
833      /**
834       * Returns an effectively unlimited stream of pseudorandom {@code
835 <     * double} values, each conforming to the given origin and bound.
835 >     * double} values from this generator and/or one split from it; each value
836 >     * conforms to the given origin (inclusive) and bound (exclusive).
837       *
838       * @implNote This method is implemented to be equivalent to {@code
839       * doubles(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
840       *
841 <     * @param randomNumberOrigin the origin of each random value
842 <     * @param randomNumberBound the bound of each random value
841 >     * @param randomNumberOrigin the origin (inclusive) of each random value
842 >     * @param randomNumberBound the bound (exclusive) of each random value
843       * @return a stream of pseudorandom {@code double} values,
844 <     * each with the given origin and bound.
844 >     *         each with the given origin (inclusive) and bound (exclusive)
845       * @throws IllegalArgumentException if {@code randomNumberOrigin}
846       *         is greater than or equal to {@code randomNumberBound}
847       */
848      public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
849 <        if (randomNumberOrigin >= randomNumberBound)
850 <            throw new IllegalArgumentException("bound must be greater than origin");
849 >        if (!(randomNumberOrigin < randomNumberBound))
850 >            throw new IllegalArgumentException(BadRange);
851          return StreamSupport.doubleStream
852              (new RandomDoublesSpliterator
853               (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
# Line 836 | Line 856 | public class SplittableRandom {
856  
857      /**
858       * Spliterator for int streams.  We multiplex the four int
859 <     * versions into one class by treating and bound < origin as
859 >     * versions into one class by treating a bound less than origin as
860       * unbounded, and also by treating "infinite" as equivalent to
861       * Long.MAX_VALUE. For splits, it uses the standard divide-by-two
862       * approach. The long and double versions of this class are
863       * identical except for types.
864       */
865 <    static class RandomIntsSpliterator implements Spliterator.OfInt {
865 >    static final class RandomIntsSpliterator implements Spliterator.OfInt {
866          final SplittableRandom rng;
867          long index;
868          final long fence;
# Line 866 | Line 886 | public class SplittableRandom {
886  
887          public int characteristics() {
888              return (Spliterator.SIZED | Spliterator.SUBSIZED |
889 <                    Spliterator.ORDERED | Spliterator.NONNULL |
870 <                    Spliterator.IMMUTABLE);
889 >                    Spliterator.NONNULL | Spliterator.IMMUTABLE);
890          }
891  
892          public boolean tryAdvance(IntConsumer consumer) {
# Line 886 | Line 905 | public class SplittableRandom {
905              long i = index, f = fence;
906              if (i < f) {
907                  index = f;
908 +                SplittableRandom r = rng;
909                  int o = origin, b = bound;
910                  do {
911 <                    consumer.accept(rng.internalNextInt(o, b));
911 >                    consumer.accept(r.internalNextInt(o, b));
912                  } while (++i < f);
913              }
914          }
# Line 897 | Line 917 | public class SplittableRandom {
917      /**
918       * Spliterator for long streams.
919       */
920 <    static class RandomLongsSpliterator implements Spliterator.OfLong {
920 >    static final class RandomLongsSpliterator implements Spliterator.OfLong {
921          final SplittableRandom rng;
922          long index;
923          final long fence;
# Line 921 | Line 941 | public class SplittableRandom {
941  
942          public int characteristics() {
943              return (Spliterator.SIZED | Spliterator.SUBSIZED |
944 <                    Spliterator.ORDERED | Spliterator.NONNULL |
925 <                    Spliterator.IMMUTABLE);
944 >                    Spliterator.NONNULL | Spliterator.IMMUTABLE);
945          }
946  
947          public boolean tryAdvance(LongConsumer consumer) {
# Line 941 | Line 960 | public class SplittableRandom {
960              long i = index, f = fence;
961              if (i < f) {
962                  index = f;
963 +                SplittableRandom r = rng;
964                  long o = origin, b = bound;
965                  do {
966 <                    consumer.accept(rng.internalNextLong(o, b));
966 >                    consumer.accept(r.internalNextLong(o, b));
967                  } while (++i < f);
968              }
969          }
# Line 953 | Line 973 | public class SplittableRandom {
973      /**
974       * Spliterator for double streams.
975       */
976 <    static class RandomDoublesSpliterator implements Spliterator.OfDouble {
976 >    static final class RandomDoublesSpliterator implements Spliterator.OfDouble {
977          final SplittableRandom rng;
978          long index;
979          final long fence;
# Line 977 | Line 997 | public class SplittableRandom {
997  
998          public int characteristics() {
999              return (Spliterator.SIZED | Spliterator.SUBSIZED |
1000 <                    Spliterator.ORDERED | Spliterator.NONNULL |
981 <                    Spliterator.IMMUTABLE);
1000 >                    Spliterator.NONNULL | Spliterator.IMMUTABLE);
1001          }
1002  
1003          public boolean tryAdvance(DoubleConsumer consumer) {
# Line 997 | Line 1016 | public class SplittableRandom {
1016              long i = index, f = fence;
1017              if (i < f) {
1018                  index = f;
1019 +                SplittableRandom r = rng;
1020                  double o = origin, b = bound;
1021                  do {
1022 <                    consumer.accept(rng.internalNextDouble(o, b));
1022 >                    consumer.accept(r.internalNextDouble(o, b));
1023                  } while (++i < f);
1024              }
1025          }
1026      }
1027  
1028   }
1009

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines