Skip to content

Instantly share code, notes, and snippets.

@ColtonPhillips
Created March 21, 2014 12:17
Show Gist options
  • Save ColtonPhillips/9684986 to your computer and use it in GitHub Desktop.
Save ColtonPhillips/9684986 to your computer and use it in GitHub Desktop.
import random
def rstr(length=5, special_chars=True, numbers=True, upper_case=True):
chars = string.ascii_lowercase
chars += string.ascii_uppercase if upper_case else ''
chars += string.digits if numbers else ''
chars += string.punctuation if special_chars else ''
return ''.join(random.choice(chars) for i in range(length))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment