import random


def roulette(total_fitness, population):
    """

    Selects a member from the popluation via roulette wheel selection
    """
    pie_slice = random.random() * total_fitness
    fitness_so_far = 0.0

    for i in range(len(population)):
        fitness_so_far += population[i].fitness

        if fitness_so_far >= pie_slice:
            return population[i]
    return None