input: Write a function to generate a random password of given length including at least one lowercase letter, one uppercase letter, one digit, and one special character.
  assert len(generate_password(8)) == 8
  assert any(c.islower() for c in generate_password(8))
  assert any(c.isupper() for c in generate_password(8))
  assert any(c.isdigit() for c in generate_password(8))
  assert any(c in "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~" for c in generate_password(8))
output: import random
  import string
  
  def generate_password(length):
      if length < 4:
          raise ValueError("Password length must be at least 4 characters.")
      
      # Ensuring at least one character from each required set
      lowercase = random.choice(string.ascii_lowercase)
      uppercase = random.choice(string.ascii_uppercase)
      digit = random.choice(string.digits)
      special = random.choice("!#$%&'()*+,-./:;<=>?@[\]^_`{|}~")
      
      # Remaining characters can be any from the full set
      remaining_length = length - 4
      all_characters = string.ascii_letters + string.digits + "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~"
      remaining_chars = [random.choice(all_characters) for _ in range(remaining_length)]
      
      # Combine all characters and shuffle
      password_list = [lowercase, uppercase, digit, special] + remaining_chars
      random.shuffle(password_list)
      
      return ''.join(password_list)