import random def mixupB(L): newL = L[:] length = len(L) for i in range(length): newIndex = random.randint(0, length-1) newL[newIndex], newL[i] = newL[i], newL[newIndex] return(newL) def mixup(L): newL = L[:] length = len(L) for i in range(length): newIndex = random.randint(i, length-1) newL[newIndex], newL[i] = newL[i], newL[newIndex] return(newL) # this can be used to test mixup. E.g. testMixup(1000000, mixupB) or testMixup(1000000, mixup) # Calls mixup n times on list [1,2,3] # and tallies the number of times each of six possible permutations was generated # What do you expect? What do you actually get? def testMixup(n, fn=mixupB): results = {(0,1,2): 0, (0,2,1): 0, (1,2,0): 0, (1, 0, 2):0, (2,0,1):0, (2, 1, 0):0} listOfInts = [0,1,2] for i in range(n): randomOrdering = tuple(fn(listOfInts)) results[randomOrdering] = results[randomOrdering] + 1 print(results) for key in results: print("{}: {:.2f}%".format(key, 100.0*(results[key]/float(n))))