input: Write a python function to generate a random password of a given length including uppercase, lowercase, digits, and special characters.
  assert len(generate_password(8)) == 8
  assert len(generate_password(12)) == 12
  assert len(generate_password(16)) == 16
output: import random
  import string
  
  def generate_password(length):
      if length < 4:
          raise ValueError("Password length must be at least 4")
      
      all_characters = string.ascii_letters + string.digits + string.punctuation
      password = [
          random.choice(string.ascii_uppercase),
          random.choice(string.ascii_lowercase),
          random.choice(string.digits),
          random.choice(string.punctuation)
      ]
      
      password += random.choices(all_characters, k=length-4)
      random.shuffle(password)
      
      return ''.join(password)