Skip to content

Instantly share code, notes, and snippets.

@ptaylor
Created March 4, 2017 14:53
Show Gist options
  • Save ptaylor/a31ac96f1d840aabacb215b3731c21a8 to your computer and use it in GitHub Desktop.
Save ptaylor/a31ac96f1d840aabacb215b3731c21a8 to your computer and use it in GitHub Desktop.
Generate random password
import random
import string
import sys
import time
import os
args = sys.argv[1:]
SLEEP_TIME = 0.01
LIMIT = 10
size = 20
if len(args) > 0:
size = int(args[0])
CHARS = string.lowercase[0:26] + string.uppercase[0:26] + string.digits[0:10]
CHARS = string.lowercase[0:6] + string.digits[0:10]
# Disable output buffering
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
sys.stdout.write("\n ")
w = ''
for i in range(0, size):
d = ''
for j in range(1, LIMIT):
d = random.SystemRandom().choice(CHARS)
sys.stdout.write(d)
time.sleep(SLEEP_TIME)
sys.stdout.write('^H')
sys.stdout.write(d)
w += d
sys.stdout.write("\n\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment