Skip to content

Instantly share code, notes, and snippets.

@seozed
Last active October 19, 2017 03:02
Show Gist options
  • Save seozed/7a3bcdccf80727c0143de91ed9d3dd86 to your computer and use it in GitHub Desktop.
Save seozed/7a3bcdccf80727c0143de91ed9d3dd86 to your computer and use it in GitHub Desktop.
生成随机字符串的方法
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)
@seozed
Copy link
Author

seozed commented Oct 19, 2017

#python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment