Skip to content

Instantly share code, notes, and snippets.

@aksiksi
Created January 16, 2012 09:20
Show Gist options
  • Save aksiksi/1619961 to your computer and use it in GitHub Desktop.
Save aksiksi/1619961 to your computer and use it in GitHub Desktop.
Generates a number of random passwords of chosen length and outputs them to a file.
from random import choice
types = [
map(chr, range(97, 123)),
map(chr, range(65, 91)),
range(0, 10)
]
def password_gen(length): # Generates a random password
password = []
for char in range(1, length+1):
password.append(choice(choice(types)))
return ''.join(map(str, password))
length = int(raw_input("Enter pass length please: "))
number = int(raw_input("Enter number of passwords to generate: "))
f = open('passwords.txt', 'w')
for a in range(1, number+1):
f.write(password_gen(length) + '\n')
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment