7 |
|
package java.util.concurrent; |
8 |
|
|
9 |
|
import java.security.SecureRandom; |
10 |
< |
import java.net.InetAddress; |
10 |
> |
import java.net.NetworkInterface; |
11 |
|
import java.io.ObjectStreamField; |
12 |
+ |
import java.util.Enumeration; |
13 |
|
import java.util.Random; |
14 |
|
import java.util.Spliterator; |
15 |
|
import java.util.concurrent.atomic.AtomicInteger; |
119 |
|
s = (s << 8) | ((long)(seedBytes[i]) & 0xffL); |
120 |
|
return s; |
121 |
|
} |
122 |
< |
int hh = 0; // hashed host address |
122 |
> |
long h = 0L; |
123 |
|
try { |
124 |
< |
hh = InetAddress.getLocalHost().hashCode(); |
124 |
> |
Enumeration<NetworkInterface> ifcs = |
125 |
> |
NetworkInterface.getNetworkInterfaces(); |
126 |
> |
boolean retry = false; // retry once if getHardwareAddress is null |
127 |
> |
while (ifcs.hasMoreElements()) { |
128 |
> |
NetworkInterface ifc = ifcs.nextElement(); |
129 |
> |
if (!ifc.isVirtual()) { // skip fake addresses |
130 |
> |
byte[] bs = ifc.getHardwareAddress(); |
131 |
> |
if (bs != null) { |
132 |
> |
int n = bs.length; |
133 |
> |
int m = Math.min(n >>> 1, 4); |
134 |
> |
for (int i = 0; i < m; ++i) |
135 |
> |
h = (h << 16) ^ (bs[i] << 8) ^ bs[n-1-i]; |
136 |
> |
if (m < 4) |
137 |
> |
h = (h << 8) ^ bs[n-1-m]; |
138 |
> |
h = mix64(h); |
139 |
> |
break; |
140 |
> |
} |
141 |
> |
else if (!retry) |
142 |
> |
retry = true; |
143 |
> |
else |
144 |
> |
break; |
145 |
> |
} |
146 |
> |
} |
147 |
|
} catch (Exception ignore) { |
148 |
|
} |
149 |
< |
return (mix64((((long)hh) << 32) ^ System.currentTimeMillis()) ^ |
149 |
> |
return (h ^ mix64(System.currentTimeMillis()) ^ |
150 |
|
mix64(System.nanoTime())); |
151 |
|
} |
152 |
|
|