input: Write a function to generate a random password of specified length containing uppercase, lowercase letters, digits, and special characters.
  assert len(generate_password(10)) == 10
  assert len(generate_password(15)) == 15
  assert any(char.isdigit() for char in generate_password(12))
  assert any(char.islower() for char in generate_password(12))
  assert any(char.isupper() for char in generate_password(12))
  assert any(char in string.punctuation for char in generate_password(12))
output: import random
  import string
  
  def generate_password(length):
      if length < 4:  # ensure there's at least one of each type of character
          raise ValueError("Password length should be at least 4")
  
      characters = string.ascii_letters + string.digits + string.punctuation
      password = [
          random.choice(string.ascii_lowercase),
          random.choice(string.ascii_uppercase),
          random.choice(string.digits),
          random.choice(string.punctuation)
      ]
  
      password += random.choices(characters, k=length - 4)
      random.shuffle(password)
      
      return ''.join(password)