Home > Mobile >  Can someone please help me with my random code generator?
Can someone please help me with my random code generator?

Time:10-24

So im trying to make a random code generator. With 16 code places like this [x1gG4...]. But if i run it it says error. Can someone help me?

#imports import random import time

#random string str_var = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"

#-----------Code print "test" print random.choice(str_var)

#just temporary time.sleep(999)

CodePudding user response:

You need to draw 16 times with replacement from str_var:

"".join([random.choice(str_var) for _ in range(16)])

CodePudding user response:

random.choice(str_var)

This will provide you with a single random character from the string you have given. The result maybe 'F'or 'g' or so on... So if you want the string of length 16 places you can iterate for 16 times.

 result=""
 for i in range(16):
    result =random.choice(str_var)
  • Related