Skip to content

Instantly share code, notes, and snippets.

@CodyKochmann
Created May 15, 2015 23:34
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 CodyKochmann/997f997b0fcc33bb3693 to your computer and use it in GitHub Desktop.
Save CodyKochmann/997f997b0fcc33bb3693 to your computer and use it in GitHub Desktop.
Generates a random string with selectable characters
def random_string(length=32,upper=True,lower=True,digits=True):
# Generates a random string with selectable characters
# By: Cody Kochmann
from random import choice
chars = ""
if upper:
chars+="QWERTYUIOPASDFGHJKLZXCVBNM"
if lower:
chars+="qwertyuiopasdfghjklzxcvbnm"
if digits:
chars+="1234567890"
return(''.join(choice(chars) for _ in range(length)))
@antlong
Copy link

antlong commented May 18, 2015

if upper:
chars += string.ascii_uppercase
if lower:
chars += string.ascii_lowercase
if digits:
chars += string.digits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment