Skip to content

Instantly share code, notes, and snippets.

@sunoru
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunoru/07448074db9f47165e96 to your computer and use it in GitHub Desktop.
Save sunoru/07448074db9f47165e96 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# -*- coding:utf-8 -*-
# filename: pwdgen.py
import sys
import string
def main():
if len(sys.argv) > 1:
l = int(sys.argv[1])
else:
l = 16
if len(sys.argv) > 2:
q = int(sys.argv[2])
else:
q = 1
op = string.ascii_letters + string.digits
ol = len(op)
for i in range(q):
with open('/dev/urandom', 'rb') as fi:
xs = fi.read(l)
a = ''
for x in xs:
a += op[x * ol // 256]
print(a)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment