On the uniform generation of random derangements
We show how to generate random derangements with the expected distribution of cycle lengths by two different techniques: random restricted transpositions and sequential importance sampling. The algorithms are simple to understand and implement and possess a performance comparable with those of currently known methods. We measure the mixing time (in the chi-square distance) of the randomized algorithm and our data indicate that τ_mix∼ O(nn), where n is the size of the derangement. The sequential importance sampling algorithm generates random derangements uniformly in O(n) time but with a small probability O(1/n) of failing.
READ FULL TEXT