package com.coding.day4;
public class 不重复验证码 {
public static String generateRandomStr(int len) {
String code = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDGFHJKLZXCVBNM";//定义字符源
String str = "";
for (int i=1; i<=4; i++) {
//循环随机获得当次字符,并移走选出的字符
String num = String.valueOf(code.charAt((int) Math.floor(Math.random() * code.length())));
str += num;
code = code.replaceAll(num,"");//将已选字符格式化
}
return str;
}
public static void main(String[] args) {
for (int i = 1; i < 2; i++) {
System.out.println("验证码为:"+generateRandomStr(4));
}
}
}
最近浏览更多
crosa_Don LV18
2022年7月6日
2196316269 LV10
2021年2月24日
xhmpmail LV17
2021年2月24日
szy2503 LV2
2020年8月10日
ma406805131 LV19
2020年6月29日
梦本是很好的啦 LV11
2020年5月28日
zhaoshaobo250 LV5
2020年3月26日
yunianzeng
2019年12月25日
暂无贡献等级
bailing162
2019年9月9日
暂无贡献等级
庄周梦蝶 LV2
2019年8月27日

最近下载
