import random


def _choose_value(values):
    """Chooses a value from the given values.

    This takes into account the respective probabilities
    of each value.

    Args:
        values: The dictionary from which to choose a value.
            For example: {"X": 1, "#": 2}

    Returns:
        A weighted, but randomly chosen value from the given
        dictionary.
    """
    # Find out maximum threshold (sum of all value probabilities)
    maximum = 0
    for value in values:
        maximum += values[value]

    # Create a random number
    choice = random.random() * maximum

    # Declare threshold -- the value that will grow until the random number is less than it
    threshold = 0

    # For every value...
    for value in values:
        # Increase the threshold by the value's probability
        threshold += values[value]

        # If the random number is less than the threshold...
        if choice < threshold:
            return value