class PasswordGenerator {

    public static String generateRandomPassword(int num) {
        Random r = new SecureRandom();
        StringBuilder password = new StringBuilder();

        //Guard for num < minLength
        if (num < minLength) {
            //Add alphanumeric chars at random
            for (int i = 0; i < minLength; i++) {
                password.append(generateAlphaNumeric(r));
            }
        } else {
            List<Character> passwordChars = new ArrayList<Character>();
            passwordChars.add(generateLowercaseChar(r));
            passwordChars.add(generateUppercaseChar(r));
            passwordChars.add(generateDigit(r));

            for (int i = passwordChars.size(); i < num; i++) {
                passwordChars.add(generateAlphaNumeric(r));
            }

            Collections.shuffle(passwordChars, new SecureRandom());

            for (char c : passwordChars) {
                password.append(c);
            }
        }

        return password.toString();
    }

}