Python生成随机密码

python3

#!/usr/bin/env python
#coding:utf-8

import random
import string

random_str = list(string.ascii_letters + string.digits + '!@#$%^&*')
print (''.join(random.sample(random_str,16)))

python2

#!/usr/bin/env python
#coding:utf-8

import string
import random
import re
list = list(string.lowercase + string.uppercase) + [ str(i) for i in range(10)]
FH = ('!','@','#','$','%','&','_')
for f in FH:
	list.append(f)
num = random.sample(list,10) 
'''随机取出10个数'''
str=''
value = str.join(num) #将取出的十个随机数进行重新合并
if not value[0].isdigit():
	print value
posted @ 2017-06-16 13:57  于欢水  阅读(475)  评论(0编辑  收藏  举报