Skip to content

Instantly share code, notes, and snippets.

@gatesphere
Created March 5, 2013 14:38
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 gatesphere/5090721 to your computer and use it in GitHub Desktop.
Save gatesphere/5090721 to your computer and use it in GitHub Desktop.
Random Password Generator in Python
#!/usr/bin/python
# this script generates a random password of length 8,
# or whatever length is passed in on the command line
from string import ascii_letters, digits, punctuation
import sys, random
chars = ascii_letters + digits + punctuation
chars = chars.replace("\\", "")
if __name__ == "__main__":
n = 8
if len(sys.argv) == 2:
n = int(sys.argv[1])
pw = "".join(random.sample(chars, n))
print pw
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment