Python v3 ( Random password generator ) -
my question is: how generate random password length varies (8 12 characters) each time generated.
this code:
import string import random def randompassword(): chars=string.ascii_uppercase + string.ascii_lowercase + string.digits size=8 return ''.join(random.choice(chars) x in range(size,12)) print(randompassword())
size = 8; range(size, 12)
returns array [8,9,10,11]
, password of length 4. instead, determine size of particular password using randint
ahead of time:
import string import random def randompassword(): chars = string.ascii_uppercase + string.ascii_lowercase + string.digits size = random.randint(8, 12) return ''.join(random.choice(chars) x in range(size))
Comments
Post a Comment