Created
February 8, 2020 09:21
-
-
Save ionling/f8bbc861e9ddfdf618bf35389e534a78 to your computer and use it in GitHub Desktop.
Generate random string with given prefix (Python3)
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 | |
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