这个是我从之前项目中看到了,觉得不错,记录一下(个人感觉简单又实用)
简单的说就是随机一个数转换成char类型,用的是ASC||编码表
public static String getRandomCode(int number) {
String codeNum = "";
int[] code = new int[3];
Random random = new Random();
for (int i = 0; i < number; i++) {
int num = random.nextInt(10) + 48;
int uppercase = random.nextInt(26) + 65;
int lowercase = random.nextInt(26) + 97;
code[0] = num;
code[1] = uppercase;
code[2] = lowercase;
codeNum += (char) code[random.nextInt(3)];
//codeNum += (char) code[random.nextInt(2)];
}
return codeNum;
}