import string
import random


def random_string(k, chars=None):
    """
    Create a random string from the set of uppercase letters and numbers.

    Parameters:
        k: int
            The length of the generated string.

        chars: iterable, optional
            The alphabet of characters from which to generate the string. By default, [A-Z0-9]

    Return:
        str
            The generated string.
    """
    if chars is None:
        chars = string.ascii_uppercase + string.digits 
    return "".join(random.choices(chars, k=k))