I know how to generate random sequence of list of numbers. Here is an example :
lst = np.arange(10) #lst always 0 .. n
np.shuffle(lst)
the question is how to shuffle the numbers so that the number ONE is NOT at position ONE, 2 is not at pos 2, and in general x is not at position x. For all 0 .. n.
The initial sequence is always 0 .. n, where n will be in hundreds, 100 or 200 or 300.
looked at the thread... the shuffle methods seem unusable, too slow. This is my current experiment, so far seems to work :
def swap(ary,pos):
new_pos = np.random.randint(pos+1, len(ary))
tmp = ary[pos]
ary[pos] = ary[new_pos]
ary[new_pos] = tmp
#print "%s <=> %s" % (pos, new_pos)
def derange(n):
lst = np.arange(n)
for i in np.arange(n-1) : swap(lst, i)
return lst