Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Random Derangement Of An Array

by Joost (Canon)
on Jul 05, 2008 at 21:46 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://695753]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-28 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found