public static Long createID() {
Random rand = new Random();
StringBuffer sb = new StringBuffer();
//等待1秒,指定根据时间毫秒数获取13位不重复数字
// try {
// Thread.sleep(1);
// } catch (InterruptedException e) {
// e.printStackTrace();
// System.out.println("生成唯一数 createID exception()");
// } finally {
// sb.append(System.currentTimeMillis() + "");
// }
//固定5位随机数
for (int i = 1; i <= 5; i++) {
//随机生成1-9自然数
int randNum = rand.nextInt(9) + 1;
sb = sb.append(randNum + "");
}
return Long.parseLong(System.currentTimeMillis() + String.valueOf(sb));
}
public static void main(String[] args) {
//压力测试生成唯一值毫秒数
long startTime = System.currentTimeMillis();
for (int i = 0; i < 3000; i++) {
System.out.println(createID());
}
long endTime = System.currentTimeMillis();
float excTime = (float) (endTime - startTime) / 1000;
System.out.println("执行时间为:" + excTime + "s");
}