根据对于uuid随机获取其index的值组成字符串。生成的字符串越长,唯一性越高。
int i = 10;
String uuid = UUID.randomUUID().toString().replace("-", "");
StringBuilder randomStr = new StringBuilder();
Random random = new Random();
for (int j = 0; j < i; j++) {
int index = random.nextInt(uuid.length());
System.out.println("获取随机下标:" + index);
randomStr.append(uuid.charAt(index));
}
System.out.println("生成" + i + "位随机数:" + randomStr);