import copy
import random
import math


def walk(collection, samples, components):
    """A sample walk with random permutations for increased similarity.

    Generates a dataset by randomly replacing a random number of components
    from one build to the next to inject aditional similarity over a simple
    random strategy.
    """

    CHANGE = 0.02

    options = []

    for _ in range(samples):
        if options:
            sample = copy.deepcopy(options[-1])

            change = random.randint(0, math.ceil(components * CHANGE))
            for _ in range(change):
                changed = random.randint(0, components - 1)
                sample[changed] = random.choice(collection)

            options.append(sample)
        else:
            options.append(random.sample(collection, components))

    return options