public static String getStrNumRandom(Integer length) {
StringBuilder str = new StringBuilder();
Random random = new Random();
for (int i = 0; i < length; i++) {
boolean b = random.nextBoolean();
if (b) { // 字符串
int choice = random.nextBoolean() ? 65 : 97; //取得65大写字母还是97小写字母
str.append((char) (choice + random.nextInt(26)));// 取得大写字母
} else { // 数字
str.append(random.nextInt(10));
}
}
return str.toString();
}
随机长度字符串
最新推荐文章于 2022-08-02 11:23:19 发布