With the same interpretation as pjs' answer (initial ordering more or less preserved), you can move a window of a given width and shuffle the underlying elements. To avoid any bias, move this window randomly.
from random import shuffle
def shuffle_window(array, width):
indexes = list(range(len(array) - width + 1))
shuffle(indexes)
for i in indexes:
window = array[i : i + width]
shuffle(window)
array[i : i + width] = window
Examples:
for width in range(6):
array = list(range(25))
shuffle_window(array, width)
print(array)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
[2, 0, 4, 1, 3, 7, 5, 6, 8, 11, 9, 12, 10, 15, 13, 14, 17, 16, 19, 18, 20, 23, 21, 24, 22]
[2, 4, 0, 3, 7, 1, 8, 6, 12, 5, 11, 10, 14, 9, 16, 15, 17, 13, 19, 18, 20, 24, 21, 22, 23]
[0, 6, 1, 2, 5, 3, 4, 12, 8, 7, 11, 9, 14, 13, 10, 16, 19, 17, 24, 23, 18, 20, 15, 21, 22]
[3, 2, 14, 6, 1, 9, 8, 12, 13, 0, 4, 15, 5, 17, 11, 16, 7, 23, 21, 20, 10, 18, 19, 22, 24]
random
module has a concept of slightly random. – Prudence