邯城往事 邯城往事

来自邯郸社畜的呐喊

目录
Python生成指定长度随机数密码文件
/  

Python生成指定长度随机数密码文件

按照指定长度和数量生成对应随机密码文件

import random
'''
# 这里要用到random函数中的随机生成一个区间的整数 randint 函数模块
'''
def generate_code(code_len):
    all_char = '0123456789qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJIKOLP!@#$%^&*()><?'
    index = len(all_char) - 1
    code = ''
    for _ in range(int(code_len)):
        num = random.randint(0,index)
        code += all_char[num]
        res = ''.join(code)
    return res
count = input('请输入你要产生多少条密码:').strip()
length = input('请输入你要产生密码的长度:').strip()
for _ in range(int(count)):
    print(generate_code(length))
    with open('passwds.txt','a+') as fw:
        fw.seek(0)
        fw.writelines(generate_code(length) + '\n')

标题:Python生成指定长度随机数密码文件
作者:cuijianzhe
地址:https://cjzshilong.cn/articles/2020/05/14/1589459519906.html