Sattolo cycle
Sattolo cycle
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
- Task
Implement the Sattolo cycle for an integer array (or, if possible, an array of any type).
Sattolo cycle is use to shuffle an array ensuring each index is in a new position.
Python
<lang python>from random import randrange
def sattoloCycle(items):
i = len(items) while i > 1: i = i - 1 j = randrange(i) # 0 <= j <= i-1 items[j], items[i] = items[i], items[j] return