input: Write a function to create a random string of a specified length using Python. The function should take an integer as input, which represents the length of the string to be generated, and return a random string consisting of alphanumeric characters (both uppercase and lowercase letters and digits).
  assert generate_string(10) != generate_string(10)
  assert len(generate_string(10)) == 10
  assert len(generate_string(15)) == 15
  assert all(c.isalnum() for c in generate_string(20))
output: import random
  import string
  
  def generate_string(length):
      return ''.join(random.choices(string.ascii_letters + string.digits, k=length))