import random
import string


def random_id(length=12) -> str:
    """
    generates a random string using the url-safe base64 characters
    (ascii letters, digits, hyphen, underscore).
    therefore, each letter adds an entropy of 6 bits (if SystemRandom can be trusted).
    :param length: the length of the random string, defaults to 12
    :return: a random string of the specified length
    """
    rand = random.SystemRandom()
    base64_chars = string.ascii_letters + string.digits + '-_'
    return ''.join(rand.choice(base64_chars) for _ in range(length))