RosettaCodeData/Task/Knuth-shuffle/Crystal/knuth-shuffle.cr
2024-10-16 18:07:41 -07:00

9 lines
152 B
Crystal

def knuthShuffle(items : Array)
i = items.size-1
while i > 1
j = Random.rand(0..i)
items.swap(i, j)
i -= 1
end
end