Mar-17-2017, 06:55 PM
Here's something basic:
import random, string, sys rand = random.SystemRandom() chars = string.ascii_letters + string.digits + string.punctuation length = int(sys.argv[1]) # if the entire password needs to be unique, just set this to 0 allowed_repetition = 2 min_unique = length - allowed_repetition pword = "" while not len(set(pword)) >= min_unique: pword = "".join(rand.choice(chars) for _ in range(length)) print(pword)