java工具类之验证码工具类

生成验证码之工具类

package cn.edu.dcxy;

import java.util.Random;

public class ItUtil {

    /**
     * 由于工具类无需创建对象,所以把其构造器私有化
     */
    private ItUtil(){

    }
    public static String createVerifyCode(int n) {
        String code = "";
        String data = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random r = new Random();
        for (int i = 0; i < n; i++) {
            int index = r.nextInt(data.length());
            code += data.charAt(index);
        }
        return code;
    }
}

  

posted @ 2022-11-21 18:11  宝山方圆  阅读(154)  评论(0编辑  收藏  举报