import random


def generate_code(code_len=6):
    """生成指定类型、长度的验证码

    Args:
        code_len (int, optional): 选择验证码的长度. Defaults to 6.

    Returns:
        Staring/int: 生成验证码
    """
    # 包含数字和字母大小写
    # all_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    # 包含数字和大写字母
    # all_chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    # 仅包含数字
    all_chars = '0123456789'
    last_ops = len(all_chars) - 1
    code = ''
    for _ in range(code_len):
        index = random.randint(0, last_ops)
        code += all_chars[index]
    return code