import random
import string
def random_char(y):
return ''.join(random.choice(string.ascii_uppercase) for x in range(y))
p1 = str(random.randrange(1, 99))
p2 = str(random_char(5))
p3 = str(random.randrange(1, 9))
p4 = str(random_char(2))
p5 = str(random.randrange(1, 9))
p6 = str(random_char(1)) # Y
p7 = str(random.randrange(1, 9)) # 7
p8 = str(random_char(3)) # AUS
result = p1 + p2+p3+p4+p5+p6+p7+p8
print(result)
I generate a specific code like "31SPZVG2CZ2R8WFU" How can i do it in a more elegant way?