Last active
October 19, 2017 03:02
-
-
Save seozed/7a3bcdccf80727c0143de91ed9d3dd86 to your computer and use it in GitHub Desktop.
生成随机字符串的方法
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 string | |
import random | |
# python 3.6.1以下 | |
text = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(15)) | |
print(text) | |
# python 3.6.1 | |
text = ''.join(random.choices(string.ascii_letters + string.digits, k=15)) | |
print(text) | |
import secrets | |
text = secrets.token_hex(15) | |
print(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#python