25 |
|
|
26 |
|
package java.util; |
27 |
|
|
28 |
– |
import java.security.SecureRandom; |
28 |
|
import java.net.NetworkInterface; |
30 |
– |
import java.util.Enumeration; |
29 |
|
import java.util.concurrent.atomic.AtomicLong; |
30 |
|
import java.util.function.IntConsumer; |
31 |
|
import java.util.function.LongConsumer; |
87 |
|
* @author Doug Lea |
88 |
|
* @since 1.8 |
89 |
|
*/ |
90 |
< |
public class SplittableRandom { |
90 |
> |
public final class SplittableRandom { |
91 |
|
|
92 |
|
/* |
93 |
|
* Implementation Overview. |
195 |
|
return z ^ (z >>> 32); |
196 |
|
} |
197 |
|
|
200 |
– |
private static long xmix64(long z) { |
201 |
– |
z *= 0xbf58476d1ce4e5b9L; |
202 |
– |
z = (z ^ (z >>> 27)) * 0x94d049bb133111ebL; |
203 |
– |
return z ^ (z >>> 31); |
204 |
– |
} |
205 |
– |
|
198 |
|
/** |
199 |
|
* Returns the 32 high bits of Stafford variant 4 mix64 function as int. |
200 |
|
*/ |
240 |
|
long h = 0L; |
241 |
|
try { |
242 |
|
Enumeration<NetworkInterface> ifcs = |
243 |
< |
NetworkInterface.getNetworkInterfaces(); |
243 |
> |
NetworkInterface.getNetworkInterfaces(); |
244 |
|
boolean retry = false; // retry once if getHardwareAddress is null |
245 |
|
while (ifcs.hasMoreElements()) { |
246 |
|
NetworkInterface ifc = ifcs.nextElement(); |
402 |
|
* may, and typically does, vary across program invocations. |
403 |
|
*/ |
404 |
|
public SplittableRandom() { // emulate defaultGen.split() |
405 |
< |
long s = defaultGen.getAndAdd(2*GOLDEN_GAMMA); |
405 |
> |
long s = defaultGen.getAndAdd(2 * GOLDEN_GAMMA); |
406 |
|
this.seed = mix64(s); |
407 |
|
this.gamma = mixGamma(s + GOLDEN_GAMMA); |
408 |
|
} |