Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Re: Re^2: When the Best Solution Isn't

by japhy (Canon)
on Sep 23, 2002 at 14:12 UTC ( #200105=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re^2: When the Best Solution Isn't
in thread When the Best Solution Isn't

Don't fret -- an equally speedy solution is thus:
sub shuffle (\@) { my $d = shift; my @r = map rand, 0 .. $#$d; @$d[sort { $r[$a] <=> $r[$b] } 0 .. $#$d] = @$d; }
It requires you send it an actual array, of course, but it is just as fast.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Re: Re: Re^2: When the Best Solution Isn't
by diotalevi (Canon) on Sep 23, 2002 at 14:40 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2019-11-22 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (113 votes). Check out past polls.

    Notices?