src/share/classes/java/util/concurrent/ThreadLocalRandom.java

Print this page

        

*** 34,45 **** */ package java.util.concurrent; import java.io.ObjectStreamField; ! import java.net.NetworkInterface; ! import java.util.Enumeration; import java.util.Random; import java.util.Spliterator; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.function.DoubleConsumer; --- 34,44 ---- */ package java.util.concurrent; import java.io.ObjectStreamField; ! import sun.security.provider.SeedGenerator; import java.util.Random; import java.util.Spliterator; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.function.DoubleConsumer;
*** 135,183 **** * The next seed for default constructors. */ private static final AtomicLong seeder = 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())); } /** * The seed increment */ --- 134,152 ---- * The next seed for default constructors. */ private static final AtomicLong seeder = 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()); } } /** * The seed increment */