Last active
July 1, 2016 18:08
-
-
Save edwinksl/77be1e4d6594a0b2071cd3b0d903d2f3 to your computer and use it in GitHub Desktop.
Password generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import math | |
import random | |
from string import digits, ascii_letters, punctuation | |
import sys | |
char_set = digits + ascii_letters + punctuation + ' ' | |
def make_password(char_num=8, char_limit=1): | |
"""Make a password of length char_num that consists of random characters in char_set variable.""" | |
if char_num > len(char_set) * char_limit: | |
char_limit = math.ceil(char_num / len(char_set)) | |
password = [] | |
while len(password) < char_num: | |
j = random.choice(char_set) | |
if password.count(j) < char_limit: | |
password.append(j) | |
return ''.join(password) | |
if __name__ == '__main__': | |
argv = [int(i) for i in sys.argv[1:3]] | |
print(make_password(*argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment