from random import Random def random_str(randomlength=31): str = '' chars = 'abcdefghijklmnopqrstuvwxyz0123456789' length = len(chars) - 1 random = Random() for i in range(randomlength): str+=chars[random.randint(0, length)] return str x = random_str() print(x)