密码至少八个字符。
密码必须仅由字母和数字组成
密码中至少包含两位数字
import random
import string
STR = string.ascii_letters
for i in range(10):
data_count = random.randint(2, 8) # 数字的个数,2到8随机
tmpAlpha_count = random.randint(1, 10) # 除掉数字,另外随机选字符的个数
alpha_count = random.randint(8 - data_count, 8 - data_count + tmpAlpha_count ) # 字符总个数
data = random.sample(string.digits, data_count)
alpha = random.sample(STR, alpha_count)
res = data + alpha
random.shuffle(res)
print(''.join(res))
用正则表达式,类似于[a-z0-9]这种,具体怎么写自己摸索吧