from typing import Optional
import random


def random_hex_color(short: Optional[bool] = False) -> str:
    """
    Generates a random hexadecimal color string.

    Arguments:
        short: If `True`, this function will generated
            a shortened 3-digit hex color, otherwise a 6-digit
            hex color will be generated instead.

    Returns:
        A three or six digit hex color of the format
            `#ff00ff` or `#f0f`.
    """
    if short:
        return "#%03x" % random.randint(0, 0xFFF)

    return "#%06x" % random.randint(0, 0xFFFFFF)