public class UuidUtil {
protected static int count=0;
public static synchronized String getUUID(){
count++;
long time = System.currentTimeMillis();
String timePattern = Long.toHexString(time);
int leftBit = 14-timePattern.length();
if(leftBit > 0){
timePattern = "0000000000".substring(0,leftBit)+timePattern;
}
String uuid = timePattern
+ Long.toHexString(Double.doubleToLongBits(Math.random()))
+ Long.toHexString(Double.doubleToLongBits(Math.random()))
+ "000000000000000000";
uuid = uuid.substring(0,32).toUpperCase();
return uuid;
}
}JAVA生成UUID主键值
最新推荐文章于 2024-08-23 09:40:50 发布
本文详细介绍了UUID生成器的实现原理,包括时间戳、随机数的处理方式,以及如何确保UUID的唯一性和安全性。
1490

被折叠的 条评论
为什么被折叠?



