import random


def select_rate(achieved_rate, slot_size):
    """
    Chooses a new rate for a demand that is lower than the achieved rate of a protocol
    :param achieved_rate: type float
        The achieved rate we want a lower rate than
    :param slot_size: type float
        The duration of a time slot in seconds
    :return: type float
    """
    rates = [1 / (slot_size * (2 ** i)) for i in range(10)]  # Rate range between
    rates = list(filter(lambda r: r < achieved_rate, rates))
    if rates:
        return random.choice(rates)
    else:
        return 0