随机生成字母串

随机生成字母串 

 public static String getRandomString(int length) { //length表示生成字符串的长度,可自行设置
        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";  //字符串内也可添加数字或符号
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(str.length());
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

猜你喜欢

转载自blog.csdn.net/qq_41991665/article/details/86575273