java生成随机字符串(A-Z0-9)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/coderALEX/article/details/78750880
public static String getRandomChar(int length) {            //生成随机字符串   
        char[] chr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
        Random random = new Random();
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < length; i++) {
        buffer.append(chr[random.nextInt(36)]);
        }
        return buffer.toString();
        }

猜你喜欢

转载自blog.csdn.net/coderALEX/article/details/78750880