Skip to content

Instantly share code, notes, and snippets.

@carterprince
Created March 30, 2017 18:29
Show Gist options
  • Save carterprince/26cd01db2aa8fdb08b150c75040b68cb to your computer and use it in GitHub Desktop.
Save carterprince/26cd01db2aa8fdb08b150c75040b68cb to your computer and use it in GitHub Desktop.
Generates a random password using common ascii numbers, letters and symbols.
import math
import random
#get user input as to how long they want the password
passwordlen = int(input("How long would you like your password to be? : "))
#our chars
chars = "abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*"
charlist = []
#couldn't figure out the split() function so I just did it with a for loop
for x in chars:
charlist.append(x)
#define password list; we can splice this back together once we are done appending
password = []
for x in range(0, passwordlen):
#this picks a random character from the charlist
ch = math.floor(random.randint(0, len(chars)))
#append the chosen character
password.append(charlist[ch])
#join the password list
print(''.join(password))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment