Skip to content

Instantly share code, notes, and snippets.

@ILoveBacteria
Created December 30, 2022 18:28
Show Gist options
  • Save ILoveBacteria/e7faf42fd7d8e47495062185df9ffabf to your computer and use it in GitHub Desktop.
Save ILoveBacteria/e7faf42fd7d8e47495062185df9ffabf to your computer and use it in GitHub Desktop.
A simple Python function that can generate a random string
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