美文网首页
python生成指定长度的验证码

python生成指定长度的验证码

作者: 以我丶之姓 | 来源:发表于2021-02-20 14:45 被阅读0次
def generate_code(code_len=4):
    """
    生成指定长度的验证码
    """
    # all_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    all_chars = '0123456789'
    last_pos = len(all_chars) - 1
    code = ''
    for i in range(code_len):
        index = random.randint(0,last_pos)
        code += all_chars[index]
    
    return code
print(generate_code(6))

相关文章

网友评论

      本文标题:python生成指定长度的验证码

      本文链接:https://www.haomeiwen.com/subject/omatfltx.html