import random


def generate_mutant(population, toolbox, family_ids, prob):
    """ Randomly select from one family one parent,
        which is employed for breeding a new individual.

    :param population: list of evolved individuals
    :param toolbox: DEAP instance for using EA operators
    :param family_ids: list of unique family ids
    :param prob: a map family ids - selection probability
    :return: a new population individual
    """
    family_ID = random.choices(family_ids, [prob[f_id] for f_id in family_ids], k=1)[0]
    family = [ind for ind in population if ind.ID == family_ID]
    parent = random.choice(family)

    child = toolbox.clone(parent)
    # try to mutate the robot until one mutation actually occurs
    while child == parent:
        child, = toolbox.mutate(child)

    # delete fitness value of the offspring inherited from its parent,
    # so that the child can be evaluated
    del child.fitness.values
    return child