python生成随机字符串(密码)

背景:通过python脚本生成生成字符串密码。

系统环境:windows11

python版本: 3.8

import random
import string


def generate_random_password(count, length):
	# string.ascii_letters 大小写字母, string.digits 为数字
	characters_long = list(string.ascii_letters + string.digits + "!@#$%^&*()")

	# 打乱字符串序列
	random.shuffle(characters_long)
	
	# 生成密码个数
	for i in range(int(count)):
		# picking random characters from the list
		password = []
		# 生成密码个数
		for b in range(length):
			password.append(random.choice(characters_long))

		# 打乱密码顺序
		random.shuffle(password)

		# 将列表转换为字符串并打印
		print("".join(password))


def main():
	length = int(input("请输入密码长度: "))
	count = int(input("请输入密码生成个数: "))
	generate_random_password(count, length)


if __name__ == '__main__':
	main()

在这里插入图片描述

参考文档
https://geekflare.com/password-generator-python-code/

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值