import random
import string
import os
#第一种方法
seed ="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-"
sa =[]
for i in range(8):
sa.append(random.choice(seed))
salt = ''.join(sa)
print salt
#第二种方法
salt =''.join(random.sample(string.ascii_letters+string.digits,8))
print salt
#第三种方法(不适用与python3.x)
temp = ''.join(map(lambda xx:(hex(ord(xx))[2:]),os.urandom(3)))
print temp
python 随机生成字符串
原创
©著作权归作者所有:来自51CTO博客作者任我行天下的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
8种超简单的Golang生成随机字符串方式
go语言中,有没有什么最快最简单的方法,用来生成只包含英文字母的随机字符串。
go语言 Bytes Golang