import random


def crossover(parent1, parent2, take_random=False):
    """ Cross-over 2 instruction sets. If take_random is False, selects just 1 point and
        takes the first part from set1 and the second from set2. If take_random is True,
        each instruction is taken from either set randomly. """

    if take_random:
        indices = [random.choice([1, 2]) for _ in parent1]
        child1 = []
        child2 = []

        for i, index in enumerate(indices):
            child1.append(parent1[i] if index == 1 else parent2[i])
            child2.append(parent1[i] if index == 2 else parent2[i])

        return child1, child2

    else:
        point = random.randrange(len(parent1))
        return parent2[point:] + parent1[:point], parent1[point:] + parent2[:point]