Created
December 30, 2022 18:28
-
-
Save ILoveBacteria/e7faf42fd7d8e47495062185df9ffabf to your computer and use it in GitHub Desktop.
A simple Python function that can generate a random string
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 random | |
import string | |
# whitespace – a string containing all ASCII whitespace | |
# ascii_lowercase – a string containing all ASCII lowercase letters | |
# ascii_uppercase – a string containing all ASCII uppercase letters | |
# ascii_letters – a string containing all ASCII letters | |
# digits – a string containing all ASCII decimal digits | |
# hexdigits – a string containing all ASCII hexadecimal digits | |
# octdigits – a string containing all ASCII octal digits | |
# punctuation – a string containing all ASCII punctuation characters | |
# printable – a string containing all ASCII characters considered printable | |
def random_string(length): | |
return ''.join(random.choices(string.ascii_letters, k=length)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment