Algorithms, Sampling.
range(iters): tmp = so_far[:] # with probability 5 / 6 if np.random.rand() <= 5 / 6: # replace a random element with the new one tmp[np.random.choice(range(len(tmp)))] = 5 cnt[frozenset(tmp)] += 1 # show normalized counts {k: v / iters for k, v in cnt.items()} we get the following output: