input: Write a function to generate a random password with a specified length and complexity.
  assert len(generate_password(8, 3)) == 8
  assert len(generate_password(12, 5)) == 12
  assert len(generate_password(6, 2)) == 8  # Minimum length is 8
  assert isinstance(generate_password(10, 4), str)
  assert generate_password(10, 6) == generate_password(10, 5)  # Maximum complexity is 5
output: import random
  import string
  
  def generate_password(length, complexity):
      if length < 8:
          length = 8
      if complexity > 5:
          complexity = 5
      
      characters = string.ascii_lowercase
      if complexity >= 2:
          characters += string.ascii_uppercase
      if complexity >= 3:
          characters += string.digits
      if complexity >= 4:
          characters += string.punctuation
  
      password = ''.join(random.choice(characters) for _ in range(length))
      return password