汪晓康

导航

生成n位的随机验证码

# 生成n位的随机验证码
import random

def Code(n=6, alph_flag=True):
	code = ''
	for i in range(n):
		rs1 = str(random.randint(0, 9))
		if alph_flag:
			rs2 = chr(random.randint(97, 122))
			rs3 = chr(random.randint(65, 90))
			rs1 = random.choice([rs1, rs2, rs3])
			code = code + rs1
	return code
print(Code(n=4, alph_flag=True))

posted on 2021-08-09 23:21  汪晓康  阅读(65)  评论(0编辑  收藏  举报