Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Random Derangement Of An Array

by Joost (Canon)
on Jul 05, 2008 at 21:46 UTC ( #695753=note: print w/replies, xml ) Need Help??


in reply to Random Derangement Of An Array

How 'bout this for an algorithm:

1. shuffle the list using List::Util's shuffle() routine.

2. swap all pairs of elements that are in their original place.

3. figure out what to do when there's an uneven number of elements in their original place (this shouldn't be hard).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://695753]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2021-03-04 16:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (105 votes). Check out past polls.

    Notices?