Created
September 6, 2012 17:19
-
-
Save esavard/3658710 to your computer and use it in GitHub Desktop.
Generate random string in Python
This file contains hidden or 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 string | |
import random | |
size = 2500 # or whatever lenght you want your random string to be | |
allowed = string.ascii_letters # add any other allowed characters here | |
randomstring = ''.join([allowed[random.randint(0, len(allowed) - 1)] for x in xrange(size)]) | |
print randomstring |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this.
To help other coders, this is how you add character sets to the allowed variable:
allowed = string.ascii_letters + string.digits
Refer: https://docs.python.org/3/library/string.html