Skip to content

Instantly share code, notes, and snippets.

@raeq
Created July 19, 2020 13:37
Show Gist options
  • Save raeq/1baf2237edbc158ebc7edacb0f590f54 to your computer and use it in GitHub Desktop.
Save raeq/1baf2237edbc158ebc7edacb0f590f54 to your computer and use it in GitHub Desktop.
Generate random strings
import string
import secrets
def generate_random_string(length: int = 0) -> str:
result = "".join(
secrets.choice(string.ascii_letters + string.digits)
for _ in range(length))
return result
assert len(generate_random_string(20)) == 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment