I dont know if it's efficient, but it works =)

# indexed array @array = sort { (-1,1)[int rand 2] } @array; # or trinary alternative @array = sort { int rand 2 ? 1 : -1 } @array;

Hope this helps

Update

In fact, it's really a bad idea to use this for randomize an array...

See the result of this script :
#!/usr/bin/perl -w use strict; my @array = qw( peach banana mango orange apple cherry ); my %result; $, = "\t\t"; $\ = "\n"; for(1..10000) { @_ = sort { (-1,1)[int rand 2] } @array; for(0..$#array) { $result{ $_[$_] , $_ }++ } } print '' , (0..$#array); for my $fruit ( @array ) { print $fruit , map { $result{ $fruit , $_ } } (0..$#array); }
Return :
0 1 2 3 4 5 peach 2982 3026 2010 1095 573 314 banana 2961 2973 1960 1172 602 332 mango 1996 2004 2333 1866 1100 701 orange 1156 1116 1914 2558 1999 1257 apple 602 561 1162 2030 3171 2474 cherry 303 320 621 1279 2555 4922
Not really randomized huh ? ...

In reply to Re: help in understanding the standard array shuffle by Gloom
in thread help in understanding the standard array shuffle by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.