package com.dev.base.exercise.oct31;
import java.util.Random;
public class VerificationCode {
public static void main(String[] args) {
String result = create();
System.out.println(result);
}
public static String create() {
String all = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char[] c = all.toCharArray();
Random r = new Random();
String s = "";
while (s.length()<6) {
int index = r.nextInt(c.length);
char c1 = c[index];
while (s.contains(c1+"")) {
index = r.nextInt(c.length);
c1 = c[index];
}
s += c1;
}
return s;
}
}
在0-9、A-Z和a-z中随机生成6位数的验证码,要求不能重复
最新推荐文章于 2021-10-28 10:26:21 发布