Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Random array sorting

by Aristotle (Chancellor)
on Sep 22, 2002 at 15:15 UTC ( #199903=note: print w/ replies, xml ) Need Help??


in reply to Random array sorting

See merlyn's reply below.

sub shuffle { my @shuffled; push @shuffed, splice(@_, rand(@_), 1) while @_; return @shuffled; } print shuffle @array;

The splice pulls a random element out of the array, which is pushed onto the new array. Repeat while there are still elements in the list.

Makeshifts last the longest.


Comment on Re: Random array sorting
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2014-07-29 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (226 votes), past polls