import re


def generate_id(name):
    """Generate a stable ID for a location from the name.

    We don't want duplicate entries for the same location. If the
    same location is listed multiple times with minor differences
    in the name (extra space, or age info in parentheses), we want
    to produce a single, consistent ID.

    """
    # Strip off parenthetical age info found in some NV location names.
    #
    # This regex only works if the age restriction follows the exact format
    # where the numeric age is followed by a "+" and is contained in
    # parentheses.
    id = re.sub(r"\([0-9]+\+\)", "", name)

    # Strip whitespace from ends.
    id = id.strip()

    # Lower-case.
    id = id.lower()

    # Only keep alphanumeric characters, hyphens, and spaces.
    id = re.sub(r"[^a-z0-9 -]", "", id)

    # Replace interior whitespace with hyphens
    id = re.sub(r"\s+", "-", id)

    return id