Module misty2py.utils.generators

This module contains generator functions.

Functions

def get_random_string(n: int) ‑> str
Expand source code
def get_random_string(n: int) -> str:
    """Constructs an `n` characters long random string containing ASCII letters and digits.

    Args:
        n (int): The required length of the string.

    Returns:
        str: The random string.
    """

    assert n > 0, "Required string length must be a positive integer."

    return "".join(
        random.SystemRandom().choice(string.ascii_letters + string.digits)
        for _ in range(n)
    )

Constructs an n characters long random string containing ASCII letters and digits.

Args

n : int
The required length of the string.

Returns

str
The random string.