44 |
|
* |
45 |
|
* <p>Instances of {@code ThreadLocalRandom} are not cryptographically |
46 |
|
* secure. Consider instead using {@link java.security.SecureRandom} |
47 |
< |
* in security-sensitive applications. Additionally, instances do not |
48 |
< |
* use a cryptographically random seed unless the {@linkplain |
49 |
< |
* System#getProperty system property} {@code |
50 |
< |
* java.util.secureRandomSeed} is set to {@code true}. |
47 |
> |
* in security-sensitive applications. |
48 |
|
* |
49 |
|
* @since 1.7 |
50 |
|
* @author Doug Lea |
102 |
|
/** |
103 |
|
* The next seed for default constructors. |
104 |
|
*/ |
105 |
< |
private static final AtomicLong seeder = new AtomicLong(initialSeed()); |
106 |
< |
|
107 |
< |
private static long initialSeed() { // same as SplittableRandom |
111 |
< |
try { // ignore exceptions in accessing/parsing properties |
112 |
< |
String pp = System.getProperty |
113 |
< |
("java.util.secureRandomSeed"); |
114 |
< |
if (pp != null && pp.equalsIgnoreCase("true")) { |
115 |
< |
byte[] seedBytes = java.security.SecureRandom.getSeed(8); |
116 |
< |
long s = (long)(seedBytes[0]) & 0xffL; |
117 |
< |
for (int i = 1; i < 8; ++i) |
118 |
< |
s = (s << 8) | ((long)(seedBytes[i]) & 0xffL); |
119 |
< |
return s; |
120 |
< |
} |
121 |
< |
} catch (Exception ignore) { |
122 |
< |
} |
123 |
< |
int hh = 0; // hashed host address |
124 |
< |
try { |
125 |
< |
hh = InetAddress.getLocalHost().hashCode(); |
126 |
< |
} catch (Exception ignore) { |
127 |
< |
} |
128 |
< |
return (mix64((((long)hh) << 32) ^ System.currentTimeMillis()) ^ |
129 |
< |
mix64(System.nanoTime())); |
130 |
< |
} |
131 |
< |
|
105 |
> |
private static final AtomicLong seeder = |
106 |
> |
new AtomicLong(mix64(System.currentTimeMillis()) ^ |
107 |
> |
mix64(System.nanoTime())); |
108 |
|
/** |
109 |
|
* The seed increment |
110 |
|
*/ |