src/share/classes/java/util/SplittableRandom.java

Print this page

        

*** 23,33 **** * questions. */ package java.util; ! import java.net.NetworkInterface; import java.util.concurrent.atomic.AtomicLong; import java.util.function.IntConsumer; import java.util.function.LongConsumer; import java.util.function.DoubleConsumer; import java.util.stream.StreamSupport; --- 23,33 ---- * questions. */ package java.util; ! import sun.security.provider.SeedGenerator; import java.util.concurrent.atomic.AtomicLong; import java.util.function.IntConsumer; import java.util.function.LongConsumer; import java.util.function.DoubleConsumer; import java.util.stream.StreamSupport;
*** 225,273 **** * The seed generator for default constructors. */ private static final AtomicLong defaultGen = new AtomicLong(initialSeed()); private static long initialSeed() { ! String pp = java.security.AccessController.doPrivileged( ! new sun.security.action.GetPropertyAction( ! "java.util.secureRandomSeed")); ! if (pp != null && pp.equalsIgnoreCase("true")) { ! byte[] seedBytes = java.security.SecureRandom.getSeed(8); long s = (long)(seedBytes[0]) & 0xffL; for (int i = 1; i < 8; ++i) s = (s << 8) | ((long)(seedBytes[i]) & 0xffL); ! return s; } - long h = 0L; - try { - Enumeration<NetworkInterface> ifcs = - NetworkInterface.getNetworkInterfaces(); - boolean retry = false; // retry once if getHardwareAddress is null - while (ifcs.hasMoreElements()) { - NetworkInterface ifc = ifcs.nextElement(); - if (!ifc.isVirtual()) { // skip fake addresses - byte[] bs = ifc.getHardwareAddress(); - if (bs != null) { - int n = bs.length; - int m = Math.min(n >>> 1, 4); - for (int i = 0; i < m; ++i) - h = (h << 16) ^ (bs[i] << 8) ^ bs[n-1-i]; - if (m < 4) - h = (h << 8) ^ bs[n-1-m]; - h = mix64(h); - break; - } - else if (!retry) - retry = true; - else - break; - } - } - } catch (Exception ignore) { - } - return (h ^ mix64(System.currentTimeMillis()) ^ - mix64(System.nanoTime())); } // IllegalArgumentException messages static final String BadBound = "bound must be positive"; static final String BadRange = "bound must be greater than origin"; --- 225,243 ---- * The seed generator for default constructors. */ private static final AtomicLong defaultGen = new AtomicLong(initialSeed()); private static long initialSeed() { ! try (SeedGenerator sg = SeedGenerator.getNativeInstance()) { ! byte[] seedBytes = new byte[8]; ! sg.getSeedBytes(seedBytes); long s = (long)(seedBytes[0]) & 0xffL; for (int i = 1; i < 8; ++i) s = (s << 8) | ((long)(seedBytes[i]) & 0xffL); ! return s ^ mix64(System.currentTimeMillis()) ^ ! mix64(System.nanoTime()); } } // IllegalArgumentException messages static final String BadBound = "bound must be positive"; static final String BadRange = "bound must be greater than origin";