import java.util.Random;
//生成有数字和字母生成的不重复的验证码 public class GenerantRandom { private static final char[] str = {‘0’,’1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’,’A’,’B’, ‘C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’,’L’,’M’,’N’, ‘O’,’P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’};
代码语言:javascript复制public static void main(String[] args) {
String validate = "";
while(true) {
char c = str[new Random().nextInt(36)];
if(!validate.contains(c "")) {
validate = c;
}
if(validate.length()==6) {
break;
}
}
System.out.println(validate);
}
}