The stupid question is the question not asked  
PerlMonks 
Re^2: Random Derangement Of An Array (rotate)by tye (Sage) 
on Jul 05, 2008 at 22:11 UTC ( #695760=note: print w/replies, xml )  Need Help?? 
Shuffle the numbers 1..$#list. Add in the number 0 (just on the end). Then break this list up into 1 or more substrings of at least 2 indices each. Rotate the items at the indices of each substring. Breaking the list up into pairs (as you did above) is one way to do that if the number of items is even. Perhaps better is to just keep it one list and rotate the whole list, as demonstrated at Re: Derangements iterator. If you remove the "at least 2 indices each" requirement then rotating gives you permutations, not derangements. Of course, not all derangements (nor permutations) are equally likely when using this technique. But it does select from the subset of derangements that are random rotations uniformly. Which method is more appropriate depends on the X of your XY problem (which you didn't specify, of course).  tye
In Section
Seekers of Perl Wisdom

