def generate_random_string(length):
 r = random.SystemRandom()
 str = ''
 chars = (string.letters + string.digits)
 while (length > 0):
  str += r.choice(chars)
  length -= 1
 return str

def generate_random_string ( length ) : r = random . SystemRandom ( ) str = '' chars = ( string . letters + string . digits ) while ( length > 0 ) : str += r . choice ( chars ) length -= 1 return str
return a random string using alphanumeric characters .