import random


def mutation (pool, pool_size, l, pm):
    """ Mutation occurs with a probability of pm on each gene of each chromosome in the pool """

    for chromes in pool:
        for gene in chromes:
            if random.uniform(0, 1) < pm:
                if ( gene == 1 ):
                    gene = 0
                else:
                    gene = 1
    return pool