from typing import Union
from typing import List
import random


def random_color(n: int = 1) -> Union[str, List]:
    """
    随机生成颜色代码

    Args:
        n: 生成颜色代码的数目。

    Returns:
        n为1时返回一个颜色代码字符串，n不为1时返回颜色代码列表。
    """
    if n <= 0:
        raise Exception(
            "Invalid param 'n' you provided, which sholud be equal or greater than 1."
        )
    colorArr = [
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
    ]
    colors = list()
    for i in range(n):
        color = ""
        for i in range(6):
            color += colorArr[random.randint(0, 14)]
        colors.append("#" + color)

    return colors if n > 1 else colors[0]