I am attempting to make an ID generator that generates 64 bit longs. The IDs needs to be globally distinctive even between two offline machines. This is similar thought as UUID (GUID), however UUID is 128 bit lengthy and comprises redundant (fixed) bits (eg. it makes use of the millisecs handed for the reason that yr 1980 and has 5-Eight versioning bits). I may use both the least or most important 64 bits of a UUID, however as a result of it comprises these fixed bits, it might not be distinctive sufficient.
So I made my very own logic. It is essential that it has to run all over the place, so I can not use MAC deal with, as a result of it isn’t at all times accessible (eg. on Android). What do you consider my code?
public class UID {
non-public static lengthy swRndVal;
non-public static Random random = new Random();
non-public static last lengthy mstsigMask = 0b11111111_00000000_00000000_00000000_00000000_00000000_00000000_00000000L;
non-public static last lengthy middleMask = 0b00000000_11111111_11111111_11111111_11111111_11111111_11111111_11111111L;
non-public static last lengthy lstsigMask = 0b00000000_00000000_00000000_00000000_00000000_00001111_11111111_11111111L;
static {
String s1 = System.getProperty("os.arch", "");
String s2 = System.getProperty("os.model", "");
String s3 = System.getProperty("java.vm.model", "");
String s4 = System.getProperty("java.class.model", "");
Random rand1 = new Random((s1+s2+s3+s4).hashCode());
Random rand2 = new Random();
swRndVal = rand1.nextLong() ^ rand2.nextLong();
}
public static lengthy getUniqueLong() (System.currentTimeMillis() & middleMask)
}