25 |
|
|
26 |
|
package java.util; |
27 |
|
|
28 |
< |
import java.net.InetAddress; |
28 |
> |
import java.security.SecureRandom; |
29 |
> |
import java.net.NetworkInterface; |
30 |
> |
import java.util.Enumeration; |
31 |
|
import java.util.concurrent.atomic.AtomicLong; |
30 |
– |
import java.util.Spliterator; |
32 |
|
import java.util.function.IntConsumer; |
33 |
|
import java.util.function.LongConsumer; |
34 |
|
import java.util.function.DoubleConsumer; |
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 |
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: |
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 |
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 bit-mixing function computes the same |
113 |
< |
* value as the "64-bit finalizer" function in Austin Appleby's |
114 |
< |
* MurmurHash3 algorithm. See |
115 |
< |
* http://code.google.com/p/smhasher/wiki/MurmurHash3 , which |
116 |
< |
* comments: "The constants for the finalizers were generated by a |
117 |
< |
* simple simulated-annealing algorithm, and both avalanche all |
118 |
< |
* bits of 'h' to within 0.25% bias." The mix32 function is |
111 |
< |
* equivalent to (int)(mix64(seed) >>> 32), but faster because it |
112 |
< |
* omits a step that doesn't contribute to result. |
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 nextGamma) uses the "Mix13" constants |
124 |
< |
* for MurmurHash3 described by David Stafford |
125 |
< |
* (http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html) |
126 |
< |
* To avoid potential weaknesses in bit-mixing transformations, we |
127 |
< |
* restrict gammas to odd values with at least 12 and no more than |
128 |
< |
* 52 bits set. Rather than rejecting candidates with too few or |
129 |
< |
* too many bits set, method nextGamma flips some bits (which has |
130 |
< |
* the effect of mapping at most 4 to any given gamma value). |
125 |
< |
* This reduces the effective set of 64bit odd gamma values by |
126 |
< |
* about 2<sup>14</sup>, a very tiny percentage, and serves as an |
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. |
138 |
|
* avalanching. |
139 |
|
* |
140 |
|
* The default (no-argument) constructor, in essence, invokes |
141 |
< |
* split() for a common "seeder" SplittableRandom. Unlike other |
142 |
< |
* cases, this split must be performed in a thread-safe manner, so |
143 |
< |
* we use an AtomicLong to represent the seed rather than use an |
144 |
< |
* explicit SplittableRandom. To bootstrap the seeder, we start |
145 |
< |
* off using a seed based on current time and host. This serves as |
146 |
< |
* a slimmed-down (and insecure) variant of SecureRandom that also |
147 |
< |
* avoids stalls that may occur when using /dev/random. |
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 |
159 |
|
*/ |
160 |
|
|
161 |
|
/** |
162 |
< |
* The initial gamma value for (unsplit) SplittableRandoms. Must |
163 |
< |
* be odd with at least 12 and no more than 52 bits set. Currently |
158 |
< |
* set to the golden ratio scaled to 64bits. |
162 |
> |
* The golden ratio scaled to 64bits, used as the initial gamma |
163 |
> |
* value for (unsplit) SplittableRandoms. |
164 |
|
*/ |
165 |
< |
private static final long INITIAL_GAMMA = 0x9e3779b97f4a7c15L; |
165 |
> |
private static final long GOLDEN_GAMMA = 0x9e3779b97f4a7c15L; |
166 |
|
|
167 |
|
/** |
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 static final double DOUBLE_UNIT = 1.0 / (1L << 53); |
171 |
> |
private static final double DOUBLE_ULP = 1.0 / (1L << 53); |
172 |
|
|
173 |
|
/** |
174 |
|
* The seed. Updated only via method nextSeed. |
189 |
|
} |
190 |
|
|
191 |
|
/** |
192 |
< |
* Computes MurmurHash3 64bit mix function. |
192 |
> |
* Computes Stafford variant 13 of 64bit mix function. |
193 |
|
*/ |
194 |
|
private static long mix64(long z) { |
195 |
< |
z = (z ^ (z >>> 33)) * 0xff51afd7ed558ccdL; |
196 |
< |
z = (z ^ (z >>> 33)) * 0xc4ceb9fe1a85ec53L; |
197 |
< |
return z ^ (z >>> 33); |
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 |
< |
* Returns the 32 high bits of mix64(z) as int. |
207 |
> |
* Returns the 32 high bits of Stafford variant 4 mix64 function as int. |
208 |
|
*/ |
209 |
|
private static int mix32(long z) { |
210 |
< |
z = (z ^ (z >>> 33)) * 0xff51afd7ed558ccdL; |
211 |
< |
return (int)(((z ^ (z >>> 33)) * 0xc4ceb9fe1a85ec53L) >>> 32); |
210 |
> |
z *= 0x62a9d9ed799705f5L; |
211 |
> |
return (int)(((z ^ (z >>> 28)) * 0xcb24d0a5c88c35b3L) >>> 32); |
212 |
|
} |
213 |
|
|
214 |
|
/** |
215 |
|
* Returns the gamma value to use for a new split instance. |
216 |
|
*/ |
217 |
< |
private static long nextGamma(long z) { |
218 |
< |
z = (z ^ (z >>> 30)) * 0xbf58476d1ce4e5b9L; // Stafford "Mix13" |
219 |
< |
z = (z ^ (z >>> 27)) * 0x94d049bb133111ebL; |
220 |
< |
z = (z ^ (z >>> 31)) | 1L; // force to be odd |
221 |
< |
int n = Long.bitCount(z); // ensure enough 0 and 1 bits |
222 |
< |
return (n < 12 || n > 52) ? z ^ 0xaaaaaaaaaaaaaaaaL : 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 |
|
/** |
232 |
|
/** |
233 |
|
* The seed generator for default constructors. |
234 |
|
*/ |
235 |
< |
private static final AtomicLong seeder = |
225 |
< |
new AtomicLong(mix64((((long)hashedHostAddress()) << 32) ^ |
226 |
< |
System.currentTimeMillis()) ^ |
227 |
< |
mix64(System.nanoTime())); |
235 |
> |
private static final AtomicLong defaultGen = new AtomicLong(initialSeed()); |
236 |
|
|
237 |
< |
/** |
238 |
< |
* Returns hash of local host IP address, if available; else 0. |
239 |
< |
*/ |
240 |
< |
private static int hashedHostAddress() { |
241 |
< |
try { |
242 |
< |
return InetAddress.getLocalHost().hashCode(); |
243 |
< |
} catch (Exception ex) { |
244 |
< |
return 0; |
245 |
< |
} |
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 |
381 |
|
* @return a pseudorandom value |
382 |
|
*/ |
383 |
|
final double internalNextDouble(double origin, double bound) { |
384 |
< |
double r = (nextLong() >>> 11) * DOUBLE_UNIT; |
384 |
> |
double r = (nextLong() >>> 11) * DOUBLE_ULP; |
385 |
|
if (origin < bound) { |
386 |
|
r = r * (bound - origin) + origin; |
387 |
|
if (r >= bound) // correct for rounding |
400 |
|
* @param seed the initial seed |
401 |
|
*/ |
402 |
|
public SplittableRandom(long seed) { |
403 |
< |
this(seed, INITIAL_GAMMA); |
403 |
> |
this(seed, GOLDEN_GAMMA); |
404 |
|
} |
405 |
|
|
406 |
|
/** |
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() { // emulate seeder.split() |
413 |
< |
this.gamma = nextGamma(this.seed = seeder.addAndGet(INITIAL_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 |
|
/** |
430 |
|
* @return the new SplittableRandom instance |
431 |
|
*/ |
432 |
|
public SplittableRandom split() { |
433 |
< |
long s = nextSeed(); |
393 |
< |
return new SplittableRandom(s, nextGamma(s)); |
433 |
> |
return new SplittableRandom(nextLong(), mixGamma(nextSeed())); |
434 |
|
} |
435 |
|
|
436 |
|
/** |
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 |
410 |
< |
* 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 the bound is less than zero |
452 |
> |
* @throws IllegalArgumentException if {@code bound} is not positive |
453 |
|
*/ |
454 |
|
public int nextInt(int bound) { |
455 |
|
if (bound <= 0) |
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 |
463 |
< |
* 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 less than zero |
504 |
> |
* @throws IllegalArgumentException if {@code bound} is not positive |
505 |
|
*/ |
506 |
|
public long nextLong(long bound) { |
507 |
|
if (bound <= 0) |
542 |
|
* (inclusive) and one (exclusive). |
543 |
|
* |
544 |
|
* @return a pseudorandom {@code double} value between zero |
545 |
< |
* (inclusive) and one (exclusive) |
545 |
> |
* (inclusive) and one (exclusive) |
546 |
|
*/ |
547 |
|
public double nextDouble() { |
548 |
< |
return (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT; |
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 |
518 |
< |
* positive. |
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 less than zero |
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(BadBound); |
563 |
< |
double result = (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT * bound; |
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 |
|
} |
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) |
576 |
|
* @throws IllegalArgumentException if {@code origin} is greater than |
595 |
|
// maintenance purposes the small differences across forms. |
596 |
|
|
597 |
|
/** |
598 |
< |
* Returns a stream producing 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 |
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)}. |
630 |
|
} |
631 |
|
|
632 |
|
/** |
633 |
< |
* Returns a stream producing 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, or {@code randomNumberOrigin} |
645 |
|
* is greater than or equal to {@code randomNumberBound} |
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 |
|
*/ |
681 |
|
} |
682 |
|
|
683 |
|
/** |
684 |
< |
* Returns a stream producing 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 pseudorandom {@code long} values |
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)}. |
717 |
|
|
718 |
|
/** |
719 |
|
* Returns a stream producing the given {@code streamSize} number of |
720 |
< |
* pseudorandom {@code long} values, each conforming to the |
721 |
< |
* given origin and bound. |
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, or {@code randomNumberOrigin} |
731 |
|
* is greater than or equal to {@code randomNumberBound} |
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 |
|
*/ |
768 |
|
|
769 |
|
/** |
770 |
|
* Returns a stream producing the given {@code streamSize} number of |
771 |
< |
* pseudorandom {@code double} values, each between zero |
772 |
< |
* (inclusive) and one (exclusive). |
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 |
787 |
|
|
788 |
|
/** |
789 |
|
* Returns an effectively unlimited stream of pseudorandom {@code |
790 |
< |
* double} values, each between zero (inclusive) and one |
791 |
< |
* (exclusive). |
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)}. |
804 |
|
|
805 |
|
/** |
806 |
|
* Returns a stream producing the given {@code streamSize} number of |
807 |
< |
* pseudorandom {@code double} values, each conforming to the |
808 |
< |
* given origin and bound. |
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 |
|
*/ |
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 |
|
*/ |