Skip to content

Instantly share code, notes, and snippets.

@ionling
Created February 8, 2020 09:21
Show Gist options
  • Save ionling/f8bbc861e9ddfdf618bf35389e534a78 to your computer and use it in GitHub Desktop.
Save ionling/f8bbc861e9ddfdf618bf35389e534a78 to your computer and use it in GitHub Desktop.
Generate random string with given prefix (Python3)
import random
import string
def random_str(prefix="", size=10) -> str:
"""Generate random string with given prefix.
Args:
prefix : Prefix of string
size : Random string's total size
"""
s = "".join(
[random.choice(string.digits + string.ascii_lowercase) for i in range(size)]
)
return (prefix + s)[:size]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment