java生成4位随机数验证码

import java.util.Random;


public class TestQrcode{
public static void main(String[] args) {
String str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
StringBuilder sb=new StringBuilder(4);
for(int i=0;i<4;i++)
{
//public int nextInt(int n) 该方法的作用是生成一个随机的int值,该值介于[0,n)的区间,也就是0到n之间的随机int值,包含0而不包含n。
char ch=str.charAt(new Random().nextInt(str.length()));
sb.append(ch);
}
System.out.println(sb.toString());
}
}

猜你喜欢

转载自blog.csdn.net/m0_37846887/article/details/80894064
今日推荐