Recently I learn how to generate UUID. I find the class TimeBasedUUIDGenerator.java in elasticsearch.
I find it use mac adress to identify current machine(MacAddressProvide.java). But it XOR the mac adress with random bytes (as the code snippet below). As I know this will make the mac adress to random and increase the probability of conflict. Why we don't use mac adress directly?
public static byte[] getSecureMungedAddress() {
byte[] address = null;
try {
address = getMacAddress();
} catch (SocketException e) {
// address will be set below
}
if (!isValidAddress(address)) {
address = constructDummyMulticastAddress();
}
byte[] mungedBytes = new byte[6];
SecureRandomHolder.INSTANCE.nextBytes(mungedBytes);
for (int i = 0; i < 6; ++i) {
mungedBytes[i] ^= address[i];
}
return mungedBytes;
}