package jnpf.fileStorage.dms;
|
|
import java.security.SecureRandom;
|
import java.util.UUID;
|
|
public final class UuidV7Generator {
|
private static final SecureRandom RANDOM = new SecureRandom();
|
|
private UuidV7Generator() {
|
}
|
|
public static UUID generate() {
|
long timestamp = System.currentTimeMillis() & 0x0000FFFFFFFFFFFFL;
|
long randomA = RANDOM.nextInt(1 << 12);
|
long mostSignificantBits = (timestamp << 16) | 0x7000L | randomA;
|
long leastSignificantBits = RANDOM.nextLong();
|
leastSignificantBits = (leastSignificantBits & 0x3FFFFFFFFFFFFFFFL)
|
| 0x8000000000000000L;
|
return new UUID(mostSignificantBits, leastSignificantBits);
|
}
|
}
|