import java.util.Random;
public class RandGenDemo {
public static void main(String[] args) {
System.out.println("请输入验证码:"+VerificationCode.codeFen());
}
}
class VerificationCode{
public static String codeFen(){
String str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char[] VerificationCodeArray = str.toCharArray();
Random random = new Random();
int count = 0;
StringBuilder stringBuilder = new StringBuilder();
while(true) {
int index = random.nextInt(VerificationCodeArray.length);
char c = VerificationCodeArray[index];
if (stringBuilder.indexOf(c + "") == -1) {
stringBuilder.append(c);
count++;
}
if (count == 4) {
break;
}
}
return stringBuilder.toString();
}
}