# inplaceshuffle.py import random import time def shuffle(x): last_idx = len(x) - 1 while last_idx: rand_idx = random.randint(0, last_idx) # 0 <= randidx <= idx # swap rand_idx and last_idx tmp = x[rand_idx] x[rand_idx] = x[last_idx] x[last_idx] = tmp last_idx = last_idx - 1 x = list(range(100000)) tick = time.clock() shuffle(x) print(time.clock() - tick)