in reply to Random Derangement Of An Array
Have a look at this thread: random derangement. Suggestions include:
- generating a random permutation until you get a derangement (expected number of tries is e), and:
- using a modification of the basic random shuffle algorithm
Update: the modification of the basic random shuffle algorithm is to swap position j with a random element from positions j through the end which doesn't violate the derangement condition.