CodyKochmann
5/15/2015 - 11:34 PM

Generates a random string with selectable characters

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)))