你们好,这个随机生成密码怎么写啊?主要是那个初始化随机数种子数为10应该设在哪里?

img


使用radom库的choice函数随机生成一个20位包含数字和字母的密码,初始化随机数种子数为10。



```python
import string  # string module里包含了阿拉伯数字,ascii码,特殊符号
import random  # 需要利用到choice

random.seed(10)  # 初始化随机种子数为10
a = int(input('请输入要求的密码长度:'))
b = string.digits + string.ascii_letters + string.punctuation  # 构建密码池
password = ""  # 初始化密码
for i in range(0, a):
    password = password + random.choice(b)  # 从密码池中随机挑选内容构建密码
print(password)  # 输出密码


```

实现代码如下,望采纳

# -*- coding: utf-8 -*-
import random
import string

all_char = string.ascii_letters + string.digits
# 随机种子
random.seed(10)
code = random.choices(all_char,k=20)
code = ''.join(code)
print(code)