[Java] 纯文本查看 复制代码
package demos;
import java.util.Random;
/*
生成随机的四位验证码:0-9,a-z,A-Z
*/
public class Demo3 {
public static final int NUM = 4;
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
System.out.print(getVerify() + " ");
if (i % 10 == 0) {
System.out.println();
}
}
}
public static String getVerify() {
String rs = "";
Random ascii = new Random();
for (int i = 0; i < NUM; i++) {
int judge = ascii.nextInt(90) + 1;
if (judge <= 30) {
rs += (char) (ascii.nextInt(10) + 48);
} else if (judge <= 60) {
rs += (char) (ascii.nextInt(26) + 65);
} else {
rs += (char) (ascii.nextInt(26) + 97);
}
}
return rs;
}
}