生成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))