Created
March 8, 2012 16:28
-
-
Save jasonwyatt/2001924 to your computer and use it in GitHub Desktop.
Random String Generator (Passwords)
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
def random_string(n_chars): | |
'''Generates a random string of length n_chars. | |
>>> random_string(5) | |
'FM>ro' | |
>>> random_string(8) | |
'"K^V]J|/' | |
>>> random_string(32) | |
')tTu,2"s`ke`MF0}qWd.-&__C8OEksQy' | |
:param n_chars: Number of characters to pick | |
:type n_chars: int | |
''' | |
return ''.join( chr(random.randrange(32, 126)) for i in xrange(n_chars) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment