Here, size=8; range(size,12) continuously returns an array [8,9,10,11], so you generally get a password of length 4. All things considered, decide the size of this specific password utilizing randint early:
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) for x in range(size))
Join the python course fast, to learn python concepts in detail and get certified.