生成8位随机大小写字母加数字随机数

public static String getRundom(){
//         48-57 65-90 97-122
        StringBuffer id=new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < 8; i++) {
            char s = 0;
            int j=random.nextInt(3) % 4;
            switch (j) {
            case 0:
                //随机生成数字
                s = (char) (random.nextInt(57) % (57 - 48 + 1) + 48);
                break;
            case 1:
                //随机生成大写字母
                s = (char) (random.nextInt(90) % (90 - 65 + 1) + 65);            
                break;
            case 2:
                //随机生成小写字母
                s = (char) (random.nextInt(122) % (122 - 97 + 1) + 97);
                break;
            }
            id.append(s);
        }
        return id.toString();
    }

 

posted @ 2017-10-21 16:39  人工-智能  阅读(5635)  评论(0编辑  收藏  举报