|
1 /* |
|
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
|
4 * |
|
5 * |
|
6 * |
|
7 * |
|
8 * |
|
9 * |
|
10 * |
|
11 * |
|
12 * |
|
13 * |
|
14 * |
|
15 * |
|
16 * |
|
17 * |
|
18 * |
|
19 * |
|
20 * |
|
21 * |
|
22 * |
|
23 * |
|
24 */ |
|
25 |
|
26 // package java.util; |
|
27 |
|
28 import java.math.BigInteger; |
|
29 import java.util.concurrent.atomic.AtomicLong; |
|
30 |
|
31 /** |
|
32 * A generator of uniform pseudorandom values applicable for use in |
|
33 * (among other contexts) isolated parallel computations that may |
|
34 * generate subtasks. Class {@code MRG32k3a} implements |
|
35 * interfaces {@link java.util.Rng} and {@link java.util.AbstractArbitrarilyJumpableRng}, |
|
36 * and therefore supports methods for producing pseudorandomly chosen |
|
37 * numbers of type {@code int}, {@code long}, {@code float}, and {@code double} |
|
38 * as well as creating new {@code Xoroshiro128PlusMRG32k3a} objects |
|
39 * by "jumping" or "leaping". |
|
40 * |
|
41 * <p>Instances {@code Xoroshiro128Plus} are <em>not</em> thread-safe. |
|
42 * They are designed to be used so that each thread as its own instance. |
|
43 * The methods {@link #jump} and {@link #leap} and {@link #jumps} and {@link #leaps} |
|
44 * can be used to construct new instances of {@code Xoroshiro128Plus} that traverse |
|
45 * other parts of the state cycle. |
|
46 * |
|
47 * <p>Instances of {@code MRG32k3a} are not cryptographically |
|
48 * secure. Consider instead using {@link java.security.SecureRandom} |
|
49 * in security-sensitive applications. Additionally, |
|
50 * default-constructed instances do not use a cryptographically random |
|
51 * seed unless the {@linkplain System#getProperty system property} |
|
52 * {@code java.util.secureRandomSeed} is set to {@code true}. |
|
53 * |
|
54 * @author Guy Steele |
|
55 * @since 1.9 |
|
56 */ |
|
57 public final class MRG32k3a extends AbstractArbitrarilyJumpableRng { |
|
58 |
|
59 /* |
|
60 * Implementation Overview. |
|
61 * |
|
62 * xxxx |
|
63 * |
|
64 * File organization: First the non-public methods that constitute |
|
65 * the main algorithm, then the main public methods, followed by |
|
66 * some custom spliterator classes needed for stream methods. |
|
67 */ |
|
68 |
|
69 private final static double norm1 = 2.328306549295728e-10; |
|
70 private final static double norm2 = 2.328318824698632e-10; |
|
71 private final static double m1 = 4294967087.0; |
|
72 private final static double m2 = 4294944443.0; |
|
73 private final static double a12 = 1403580.0; |
|
74 private final static double a13n = 810728.0; |
|
75 private final static double a21 = 527612.0; |
|
76 private final static double a23n = 1370589.0; |
|
77 private final static int m1_deficit = 209; |
|
78 |
|
79 // IllegalArgumentException messages |
|
80 private static final String BadLogDistance = "logDistance must be non-negative and not greater than 192"; |
|
81 |
|
82 /** |
|
83 * The per-instance state. |
|
84 The seeds for s10, s11, s12 must be integers in [0, m1 - 1] and not all 0. |
|
85 The seeds for s20, s21, s22 must be integers in [0, m2 - 1] and not all 0. |
|
86 */ |
|
87 private double s10, s11, s12, |
|
88 s20, s21, s22; |
|
89 |
|
90 /** |
|
91 * The seed generator for default constructors. |
|
92 */ |
|
93 private static final AtomicLong defaultGen = new AtomicLong(RngSupport.initialSeed()); |
|
94 |
|
95 /* |
|
96 32-bits Random number generator U(0,1): MRG32k3a |
|
97 Author: Pierre L'Ecuyer, |
|
98 Source: Good Parameter Sets for Combined Multiple Recursive Random |
|
99 Number Generators, |
|
100 Shorter version in Operations Research, |
|
101 47, 1 (1999), 159--164. |
|
102 --------------------------------------------------------- |
|
103 */ |
|
104 |
|
105 private void nextState() { |
|
106 /* Component 1 */ |
|
107 double p1 = a12 * s11 - a13n * s10; |
|
108 double k1 = p1 / m1; p1 -= k1 * m1; if (p1 < 0.0) p1 += m1; |
|
109 s10 = s11; s11 = s12; s12 = p1; |
|
110 /* Component 2 */ |
|
111 double p2 = a21 * s22 - a23n * s20; |
|
112 double k2 = p2 / m2; p2 -= k2 * m2; if (p2 < 0.0) p2 += m2; |
|
113 s20 = s21; s21 = s22; s22 = p2; |
|
114 } |
|
115 |
|
116 |
|
117 /** |
|
118 * The form of nextInt used by IntStream Spliterators. |
|
119 * Exactly the same as long version, except for types. |
|
120 * |
|
121 * @param origin the least value, unless greater than bound |
|
122 * @param bound the upper bound (exclusive), must not equal origin |
|
123 * @return a pseudorandom value |
|
124 */ |
|
125 protected int internalNextInt(int origin, int bound) { |
|
126 if (origin < bound) { |
|
127 final int n = bound - origin; |
|
128 final int m = n - 1; |
|
129 if (n > 0) { |
|
130 int r; |
|
131 for (int u = (int)nextDouble() >>> 1; |
|
132 u + m + ((m1_deficit + 1) >>> 1) - (r = u % n) < 0; |
|
133 u = (int)nextDouble() >>> 1) |
|
134 ; |
|
135 return (r + origin); |
|
136 } else { |
|
137 return RngSupport.boundedNextInt(this, origin, bound); |
|
138 } |
|
139 } else { |
|
140 return nextInt(); |
|
141 } |
|
142 } |
|
143 |
|
144 protected int internalNextInt(int bound) { |
|
145 // Specialize internalNextInt for origin == 0, bound > 0 |
|
146 final int n = bound; |
|
147 final int m = n - 1; |
|
148 int r; |
|
149 for (int u = (int)nextDouble() >>> 1; |
|
150 u + m + ((m1_deficit + 1) >>> 1) - (r = u % n) < 0; |
|
151 u = (int)nextDouble() >>> 1) |
|
152 ; |
|
153 return r; |
|
154 } |
|
155 |
|
156 /** |
|
157 * Constructor used by all others except default constructor. |
|
158 * All arguments must be known to be nonnegative integral values. |
|
159 */ |
|
160 private MRG32k3a(double s10, double s11, double s12, |
|
161 double s20, double s21, double s22) { |
|
162 this.s10 = s10; this.s11 = s11; this.s12 = s12; |
|
163 this.s20 = s20; this.s21 = s21; this.s22 = s22; |
|
164 if ((s10 == 0.0) && (s11 == 0.0) && (s12 == 0.0)) this.s10 = 12345.0; |
|
165 if ((s20 == 0.0) && (s21 == 0.0) && (s22 == 0.0)) this.s20 = 12345.0; |
|
166 } |
|
167 |
|
168 /* ---------------- public methods ---------------- */ |
|
169 |
|
170 public MRG32k3a(int s10, int s11, int s12, |
|
171 int s20, int s21, int s22) { |
|
172 this(((double)(((long)s10) & 0x00000000ffffffffL)) % m1, |
|
173 ((double)(((long)s11) & 0x00000000ffffffffL)) % m1, |
|
174 ((double)(((long)s12) & 0x00000000ffffffffL)) % m1, |
|
175 ((double)(((long)s20) & 0x00000000ffffffffL)) % m2, |
|
176 ((double)(((long)s21) & 0x00000000ffffffffL)) % m2, |
|
177 ((double)(((long)s22) & 0x00000000ffffffffL)) % m2); |
|
178 } |
|
179 |
|
180 /** |
|
181 * Creates a new MRG32k3a instance using the specified |
|
182 * initial seed. MRG32k3a instances created with the same |
|
183 * seed in the same program generate identical sequences of values. |
|
184 * An argument of 0 seeds the generator to a widely used initialization |
|
185 * of MRG32k3a: all six state variables are set to 12345. |
|
186 * |
|
187 * @param seed the initial seed |
|
188 */ |
|
189 public MRG32k3a(long seed) { |
|
190 this((double)((seed & 0x7FF) + 12345), |
|
191 (double)(((seed >>> 11) & 0x7FF) + 12345), |
|
192 (double)(((seed >>> 22) & 0x7FF) + 12345), |
|
193 (double)(((seed >>> 33) & 0x7FF) + 12345), |
|
194 (double)(((seed >>> 44) & 0x7FF) + 12345), |
|
195 (double)((seed >>> 55) + 12345)); |
|
196 } |
|
197 |
|
198 /** |
|
199 * Creates a new MRG32k3a instance that is likely to |
|
200 * generate sequences of values that are statistically independent |
|
201 * of those of any other instances in the current program; and |
|
202 * may, and typically does, vary across program invocations. |
|
203 */ |
|
204 public MRG32k3a() { |
|
205 this(defaultGen.getAndAdd(RngSupport.GOLDEN_RATIO_64)); |
|
206 } |
|
207 |
|
208 /** |
|
209 * Creates a new instance of {@code Xoshiro256StarStar} using the specified array of |
|
210 * initial seed bytes. Instances of {@code Xoshiro256StarStar} created with the same |
|
211 * seed array in the same program execution generate identical sequences of values. |
|
212 * |
|
213 * @param seed the initial seed |
|
214 */ |
|
215 public MRG32k3a(byte[] seed) { |
|
216 // Convert the seed to 6 int values. |
|
217 int[] data = RngSupport.convertSeedBytesToInts(seed, 6, 0); |
|
218 int s10 = data[0], s11 = data[1], s12 = data[2]; |
|
219 int s20 = data[3], s21 = data[4], s22 = data[5]; |
|
220 this.s10 = ((double)(((long)s10) & 0x00000000ffffffffL)) % m1; |
|
221 this.s11 = ((double)(((long)s11) & 0x00000000ffffffffL)) % m1; |
|
222 this.s12 = ((double)(((long)s12) & 0x00000000ffffffffL)) % m1; |
|
223 this.s20 = ((double)(((long)s20) & 0x00000000ffffffffL)) % m2; |
|
224 this.s21 = ((double)(((long)s21) & 0x00000000ffffffffL)) % m2; |
|
225 this.s22 = ((double)(((long)s22) & 0x00000000ffffffffL)) % m2; |
|
226 if ((s10 == 0.0) && (s11 == 0.0) && (s12 == 0.0)) this.s10 = 12345.0; |
|
227 if ((s20 == 0.0) && (s21 == 0.0) && (s22 == 0.0)) this.s20 = 12345.0; |
|
228 } |
|
229 |
|
230 public MRG32k3a copy() { return new MRG32k3a(s10, s11, s12, s20, s21, s22); } |
|
231 |
|
232 /** |
|
233 * Returns a pseudorandom {@code double} value between zero |
|
234 * (exclusive) and one (exclusive). |
|
235 * |
|
236 * @return a pseudorandom {@code double} value between zero |
|
237 * (exclusive) and one (exclusive) |
|
238 */ |
|
239 public double nextOpenDouble() { |
|
240 nextState(); |
|
241 double p1 = s12, p2 = s22; |
|
242 if (p1 <= p2) |
|
243 return ((p1 - p2 + m1) * norm1); |
|
244 else |
|
245 return ((p1 - p2) * norm1); |
|
246 } |
|
247 |
|
248 /** |
|
249 * Returns a pseudorandom {@code double} value between zero |
|
250 * (inclusive) and one (exclusive). |
|
251 * |
|
252 * @return a pseudorandom {@code double} value between zero |
|
253 * (inclusive) and one (exclusive) |
|
254 */ |
|
255 public double nextDouble() { |
|
256 nextState(); |
|
257 double p1 = s12, p2 = s22; |
|
258 final double p = p1 * norm1 - p2 * norm2; |
|
259 if (p < 0.0) return (p + 1.0); |
|
260 else return p; |
|
261 } |
|
262 |
|
263 |
|
264 /** |
|
265 * Returns a pseudorandom {@code float} value between zero |
|
266 * (inclusive) and one (exclusive). |
|
267 * |
|
268 * @return a pseudorandom {@code float} value between zero |
|
269 * (inclusive) and one (exclusive) |
|
270 */ |
|
271 public float nextFloat() { |
|
272 return (float)nextDouble(); |
|
273 } |
|
274 |
|
275 /** |
|
276 * Returns a pseudorandom {@code int} value. |
|
277 * |
|
278 * @return a pseudorandom {@code int} value |
|
279 */ |
|
280 public int nextInt() { |
|
281 return (internalNextInt(0x10000) << 16) | internalNextInt(0x10000); |
|
282 } |
|
283 |
|
284 /** |
|
285 * Returns a pseudorandom {@code long} value. |
|
286 * |
|
287 * @return a pseudorandom {@code long} value |
|
288 */ |
|
289 |
|
290 public long nextLong() { |
|
291 return (((long)internalNextInt(0x200000) << 43) | |
|
292 ((long)internalNextInt(0x200000) << 22) | |
|
293 ((long)internalNextInt(0x400000))); |
|
294 } |
|
295 |
|
296 // Period is (m1**3 - 1)(m2**3 - 1)/2, or approximately 2**191. |
|
297 static BigInteger calculateThePeriod() { |
|
298 BigInteger bigm1 = BigInteger.valueOf((long)m1); |
|
299 BigInteger bigm2 = BigInteger.valueOf((long)m2); |
|
300 BigInteger t1 = bigm1.multiply(bigm1).multiply(bigm1).subtract(BigInteger.ONE); |
|
301 BigInteger t2 = bigm2.multiply(bigm2).multiply(bigm2).subtract(BigInteger.ONE); |
|
302 return t1.shiftRight(1).multiply(t2); |
|
303 } |
|
304 static final BigInteger thePeriod = calculateThePeriod(); |
|
305 public BigInteger period() { return thePeriod; } |
|
306 |
|
307 // Jump and leap distances recommended in Section 1.3 of this paper: |
|
308 // Pierre L'Ecuyer, Richard Simard, E. Jack Chen, and W. David Kelton. |
|
309 // An Object-Oriented Random-Number Package with Many Long Streams and Substreams. |
|
310 // Operations Research 50, 6 (Nov--Dec 2002), 1073--1075. |
|
311 |
|
312 public double defaultJumpDistance() { return 0x1.0p76; } // 2**76 |
|
313 public double defaultLeapDistance() { return 0x1.0p127; } // 2**127 |
|
314 |
|
315 public void jump(double distance) { |
|
316 if (distance < 0.0 || Double.isInfinite(distance) || distance != Math.floor(distance)) |
|
317 throw new IllegalArgumentException("jump distance must be a nonnegative finite integer"); |
|
318 // We will compute a jump transformation (s => M s) for each LCG. |
|
319 // We initialize each transformation to the identity transformation. |
|
320 // Each will be turned into the d'th power of the corresponding base transformation. |
|
321 long m1_00 = 1, m1_01 = 0, m1_02 = 0, |
|
322 m1_10 = 0, m1_11 = 1, m1_12 = 0, |
|
323 m1_20 = 0, m1_21 = 0, m1_22 = 1; |
|
324 long m2_00 = 1, m2_01 = 0, m2_02 = 0, |
|
325 m2_10 = 0, m2_11 = 1, m2_12 = 0, |
|
326 m2_20 = 0, m2_21 = 0, m2_22 = 1; |
|
327 // These are the base transformations, which will be repeatedly squared, |
|
328 // and composed with the computed transformations for each 1-bit in distance. |
|
329 long t1_00 = 0, t1_01 = 1, t1_02 = 0, |
|
330 t1_10 = 0, t1_11 = 0, t1_12 = 1, |
|
331 t1_20 = -(long)a13n, t1_21 = (long)a12, t1_22 = 0; |
|
332 long t2_00 = 0, t2_01 = 1, t2_02 = 0, |
|
333 t2_10 = 0, t2_11 = 0, t2_12 = 1, |
|
334 t2_20 = -(long)a23n, t2_21 = (long)a21, t2_22 = 0; |
|
335 while (distance > 0.0) { |
|
336 final double dhalf = 0.5 * distance; |
|
337 if (Math.floor(dhalf) != dhalf) { |
|
338 // distance is odd: accumulate current squaring |
|
339 final long n1_00 = m1_00 * t1_00 + m1_01 * t1_10 + m1_02 * t1_20; |
|
340 final long n1_01 = m1_00 * t1_01 + m1_01 * t1_11 + m1_02 * t1_21; |
|
341 final long n1_02 = m1_00 * t1_02 + m1_01 * t1_12 + m1_02 * t1_22; |
|
342 final long n1_10 = m1_10 * t1_00 + m1_11 * t1_10 + m1_12 * t1_20; |
|
343 final long n1_11 = m1_10 * t1_01 + m1_11 * t1_11 + m1_12 * t1_21; |
|
344 final long n1_12 = m1_10 * t1_02 + m1_11 * t1_12 + m1_12 * t1_22; |
|
345 final long n1_20 = m1_20 * t1_00 + m1_21 * t1_10 + m1_22 * t1_20; |
|
346 final long n1_21 = m1_20 * t1_01 + m1_21 * t1_11 + m1_22 * t1_21; |
|
347 final long n1_22 = m1_20 * t1_02 + m1_21 * t1_12 + m1_22 * t1_22; |
|
348 m1_00 = Math.floorMod(n1_00, (long)m1); |
|
349 m1_01 = Math.floorMod(n1_01, (long)m1); |
|
350 m1_02 = Math.floorMod(n1_02, (long)m1); |
|
351 m1_10 = Math.floorMod(n1_10, (long)m1); |
|
352 m1_11 = Math.floorMod(n1_11, (long)m1); |
|
353 m1_12 = Math.floorMod(n1_12, (long)m1); |
|
354 m1_20 = Math.floorMod(n1_20, (long)m1); |
|
355 m1_21 = Math.floorMod(n1_21, (long)m1); |
|
356 m1_22 = Math.floorMod(n1_22, (long)m1); |
|
357 final long n2_00 = m2_00 * t2_00 + m2_01 * t2_10 + m2_02 * t2_20; |
|
358 final long n2_01 = m2_00 * t2_01 + m2_01 * t2_11 + m2_02 * t2_21; |
|
359 final long n2_02 = m2_00 * t2_02 + m2_01 * t2_12 + m2_02 * t2_22; |
|
360 final long n2_10 = m2_10 * t2_00 + m2_11 * t2_10 + m2_12 * t2_20; |
|
361 final long n2_11 = m2_10 * t2_01 + m2_11 * t2_11 + m2_12 * t2_21; |
|
362 final long n2_12 = m2_10 * t2_02 + m2_11 * t2_12 + m2_12 * t2_22; |
|
363 final long n2_20 = m2_20 * t2_00 + m2_21 * t2_10 + m2_22 * t2_20; |
|
364 final long n2_21 = m2_20 * t2_01 + m2_21 * t2_11 + m2_22 * t2_21; |
|
365 final long n2_22 = m2_20 * t2_02 + m2_21 * t2_12 + m2_22 * t2_22; |
|
366 m2_00 = Math.floorMod(n2_00, (long)m2); |
|
367 m2_01 = Math.floorMod(n2_01, (long)m2); |
|
368 m2_02 = Math.floorMod(n2_02, (long)m2); |
|
369 m2_10 = Math.floorMod(n2_10, (long)m2); |
|
370 m2_11 = Math.floorMod(n2_11, (long)m2); |
|
371 m2_12 = Math.floorMod(n2_12, (long)m2); |
|
372 m2_20 = Math.floorMod(n2_20, (long)m2); |
|
373 m2_21 = Math.floorMod(n2_21, (long)m2); |
|
374 m2_22 = Math.floorMod(n2_22, (long)m2); |
|
375 } |
|
376 // Square the base transformations. |
|
377 { |
|
378 final long z1_00 = m1_00 * m1_00 + m1_01 * m1_10 + m1_02 * m1_20; |
|
379 final long z1_01 = m1_00 * m1_01 + m1_01 * m1_11 + m1_02 * m1_21; |
|
380 final long z1_02 = m1_00 * m1_02 + m1_01 * m1_12 + m1_02 * m1_22; |
|
381 final long z1_10 = m1_10 * m1_00 + m1_11 * m1_10 + m1_12 * m1_20; |
|
382 final long z1_11 = m1_10 * m1_01 + m1_11 * m1_11 + m1_12 * m1_21; |
|
383 final long z1_12 = m1_10 * m1_02 + m1_11 * m1_12 + m1_12 * m1_22; |
|
384 final long z1_20 = m1_20 * m1_00 + m1_21 * m1_10 + m1_22 * m1_20; |
|
385 final long z1_21 = m1_20 * m1_01 + m1_21 * m1_11 + m1_22 * m1_21; |
|
386 final long z1_22 = m1_20 * m1_02 + m1_21 * m1_12 + m1_22 * m1_22; |
|
387 m1_00 = Math.floorMod(z1_00, (long)m1); |
|
388 m1_01 = Math.floorMod(z1_01, (long)m1); |
|
389 m1_02 = Math.floorMod(z1_02, (long)m1); |
|
390 m1_10 = Math.floorMod(z1_10, (long)m1); |
|
391 m1_11 = Math.floorMod(z1_11, (long)m1); |
|
392 m1_12 = Math.floorMod(z1_12, (long)m1); |
|
393 m1_20 = Math.floorMod(z1_20, (long)m1); |
|
394 m1_21 = Math.floorMod(z1_21, (long)m1); |
|
395 m1_22 = Math.floorMod(z1_22, (long)m1); |
|
396 final long z2_00 = m2_00 * m2_00 + m2_01 * m2_10 + m2_02 * m2_20; |
|
397 final long z2_01 = m2_00 * m2_01 + m2_01 * m2_11 + m2_02 * m2_21; |
|
398 final long z2_02 = m2_00 * m2_02 + m2_01 * m2_12 + m2_02 * m2_22; |
|
399 final long z2_10 = m2_10 * m2_00 + m2_11 * m2_10 + m2_12 * m2_20; |
|
400 final long z2_11 = m2_10 * m2_01 + m2_11 * m2_11 + m2_12 * m2_21; |
|
401 final long z2_12 = m2_10 * m2_02 + m2_11 * m2_12 + m2_12 * m2_22; |
|
402 final long z2_20 = m2_20 * m2_00 + m2_21 * m2_10 + m2_22 * m2_20; |
|
403 final long z2_21 = m2_20 * m2_01 + m2_21 * m2_11 + m2_22 * m2_21; |
|
404 final long z2_22 = m2_20 * m2_02 + m2_21 * m2_12 + m2_22 * m2_22; |
|
405 m2_00 = Math.floorMod(z2_00, (long)m2); |
|
406 m2_01 = Math.floorMod(z2_01, (long)m2); |
|
407 m2_02 = Math.floorMod(z2_02, (long)m2); |
|
408 m2_10 = Math.floorMod(z2_10, (long)m2); |
|
409 m2_11 = Math.floorMod(z2_11, (long)m2); |
|
410 m2_12 = Math.floorMod(z2_12, (long)m2); |
|
411 m2_20 = Math.floorMod(z2_20, (long)m2); |
|
412 m2_21 = Math.floorMod(z2_21, (long)m2); |
|
413 m2_22 = Math.floorMod(z2_22, (long)m2); |
|
414 } |
|
415 // Divide distance by 2. |
|
416 distance = dhalf; |
|
417 } |
|
418 final long w10 = m1_00 * (long)s10 + m1_01 * (long)s11 + m1_02 * (long)s12; |
|
419 final long w11 = m1_10 * (long)s10 + m1_11 * (long)s11 + m1_12 * (long)s12; |
|
420 final long w12 = m1_20 * (long)s10 + m1_21 * (long)s11 + m1_22 * (long)s12; |
|
421 s10 = Math.floorMod(w10, (long)m1); |
|
422 s11 = Math.floorMod(w11, (long)m1); |
|
423 s12 = Math.floorMod(w12, (long)m1); |
|
424 final long w20 = m2_00 * (long)s20 + m2_01 * (long)s21 + m2_02 * (long)s22; |
|
425 final long w21 = m2_10 * (long)s20 + m2_11 * (long)s21 + m2_12 * (long)s22; |
|
426 final long w22 = m2_20 * (long)s20 + m2_21 * (long)s21 + m2_22 * (long)s22; |
|
427 s20 = Math.floorMod(w20, (long)m2); |
|
428 s21 = Math.floorMod(w21, (long)m2); |
|
429 s22 = Math.floorMod(w22, (long)m2); |
|
430 } |
|
431 |
|
432 /** |
|
433 * Alter the state of this pseudorandom number generator so as to |
|
434 * jump forward a distance equal to 2<sup>{@code logDistance}</sup> |
|
435 * within its state cycle. |
|
436 * |
|
437 * @param logDistance the base-2 logarithm of the distance to jump |
|
438 * forward within the state cycle. Must be non-negative and |
|
439 * not greater than 192. |
|
440 * @throws IllegalArgumentException if {@code logDistance} is |
|
441 * less than zero or 2<sup>{@code logDistance}</sup> is |
|
442 * greater than the period of this generator |
|
443 */ |
|
444 public void jumpPowerOfTwo(int logDistance) { |
|
445 if (logDistance < 0 || logDistance > 192) |
|
446 throw new IllegalArgumentException(BadLogDistance); |
|
447 jump(Math.scalb(1.0, logDistance)); |
|
448 } |
|
449 |
|
450 } |