//随机生成 1-10位随机字符串
public static String getRandomString() { //length表示生成字符串的长度
String base = "abcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
//随机生成字符串长度
int length = random.nextInt(10);
StringBuffer sb = new StringBuffer();
for (int i = 1; i < length; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();
}
java随机生成字符串
最新推荐文章于 2024-07-15 03:25:54 发布