import random


def swap_random(seq, noise=0.25, max_nodes=12):
    """Swaps two locations randomly in a list.
     modified code from
     stackoverflow.com/questions/47724017/swap-two-values-randomly-in-list
    """
    # Swap makes no sense if less than 3 items.
    if len(seq) <= 3:
        return seq
    # Sometimes we dont want to randomly swap.
    if random.random() > noise:
        return seq[:max_nodes]
    idx = range(len(seq))
    i1, i2 = random.sample(idx, 2)
    seq[i1], seq[i2] = seq[i2], seq[i1]
    return seq[:max_nodes]