Created
November 18, 2016 12:54
-
-
Save rafaelsierra/916ff20df0a802b9c59ef3a827644b93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import string | |
def generate_random_string(length, stringset=string.ascii_letters+string.digits+string.punctuation): | |
''' | |
Returns a string with `length` characters chosen from `stringset` | |
>>> len(generate_random_string(20)) == 20 | |
''' | |
return ''.join([stringset[i%len(stringset)] \ | |
for i in [ord(x) for x in os.urandom(length)]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment