随机数

package com.day14;

public class Demo01 {
    public static char[] demo01(){
        int i = 1234567890;
        String s ="qwertyuiopasdfghjklzxcvbnm";
        String S=s.toUpperCase();
        String word=s+S+i;
        char[] c=word.toCharArray();

        return c;
    }
}
package com.day14;
import java.util.Random;
public class Demo02 {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            String s = verifyCode();
            System.out.println(s);
        }
    }
    public static String verifyCode(){

        char[] c=Demo01.demo01();//获取包含26个字母大小写和数字的字符数组
//        System.out.println(Arrays.toString(c));

        Random rd = new Random();
        String code="";
        for (int k = 0; k <= 6; k++) {
            int index = rd.nextInt(c.length);//随机获取数组长度作为索引
            code+=c[index];//循环添加到字符串后面
        }
        return code;
    }
}

随机数