15位随机密码生成器 (包含特殊字符、数字和字母)
当然可以,以下是一个随机生成15位密码的Python代码示例:
import random
import string
# 定义特殊字符、数字和字母的集合
special_chars = '!@#$%^&*()_+-='
digits = '0123456789'
letters = string.ascii_letters
# 定义密码长度
password_length = 15
# 从上述集合中随机选择一个字符
def random_char(char_set):
return random.choice(char_set)
# 生成密码
password = ''
for i in range(password_length):
if i % 3 == 0:
password += random_char(special_chars)
elif i % 3 == 1:
password += random_char(digits)
else:
password += random_char(letters)
# 打印生成的密码
print('Your random password is:', password)
这个代码生成的密码包含特殊字符、数字和字母,长度为15位。每三个字符中,第一个是特殊字符,第二个是数字,第三个是字母。你可以根据需要修改字符集合和密码长度。
原文地址: https://www.cveoy.top/t/topic/nO4i 著作权归作者所有。请勿转载和采集!