随机字符串生成


    private static final String BASIC = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";

    public static String randomString(int length){
        char[] basicArray = BASIC.toCharArray();
        Random random = new Random();
        char[] result = new char[length];
        for (int i = 0; i < result.length; i++) {
            int index = random.nextInt(100) % (basicArray.length);
            result[i] = basicArray[index];
        }
        return new String(result);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 6; i++) {
            System.out.println(randomString(6));
        }
    }

你可能感兴趣的:(java,开发语言)