刘光辉
昨天 bb638871a7fb692d80f1b7a758f991dc0879002c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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);
    }
}