import string
import random


def random_str(length: int = 20, has_num: bool = False) -> str:
    """
    generate a random str and len == length
    :param length: the random str`length, default=20
    :param has_num: has int?
    :return: str
    """

    all_char = string.ascii_lowercase + string.ascii_uppercase
    if has_num:
        all_char += string.digits

    lis = list()
    for _ in range(length):
        lis.extend(random.choices(all_char, k=1))
    return ''.join(lis)