Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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 musing on the Monastery: (10)
As of 2014-08-22 08:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (151 votes), past polls