<s>[INST] def generate_password(length):
    """Generate a random password of a given length."""
    import random
    import string

    if length < 8:
        print("Password length should be at least 8 characters.")
        return None

    all_characters = string.ascii_letters + string.digits + string.punctuation
    if length < 12:
        password = ''.join(random.choice(all_characters) for i in range(length))
    else:
        password = ''.join(random.choice(all_characters) for i in range(length - 3))
        password += random.choice(string.ascii_lowercase)
        password += random.choice(string.ascii_uppercase)
        password += random.choice(string.digits)

    return password[/INST]