import string
import random


def generate_uid(chars: int = 8, letters=True, special_chars=False):
    """
    Support function for :func:`Client.get_ai_response`. Generates a random string of characters to be used as a unique identifier for a user.

    Parameters
    ----------

    chars: Optional[:class:`int`]
        The number of characters to generate. Defaults to 8.

    letters: Optional[:class:`bool`]
        Whether or not to include letters. Defaults to True.

    special_chars: Optional[:class:`bool`]
        Whether or not to include special characters. Defaults to False.

    Returns
    -------

    :class:`str`
        The generated UID.
    """
    characters = string.digits

    if special_chars:
        characters = characters + string.punctuation

    if letters:
        characters = characters + string.ascii_letters

    uid = "".join(random.choice(characters) for i in range(chars))
    return uid