RosettaCodeData/Task/Knuth_shuffle/Python/knuth_shuffle.py
Ingy döt Net 1e05ecd7ee First commit of partial RosettaCode contents.
Pushing this for testing purposes. Lots of work still needed.
2013-04-08 13:02:41 -07:00

10 lines
210 B
Python

from random import randrange
def knuth_shuffle(x):
for i in range(len(x)-1, 0, -1):
j = randrange(i + 1)
x[i], x[j] = x[j], x[i]
x = list(range(10))
knuth_shuffle(x)
print("shuffled:", x)