[Chicago-talk] Random first numbers

Steven Lembark lembark at wrkhors.com
Fri May 21 10:31:17 PDT 2010


On Mon, 17 May 2010 18:29:51 -0500
Alan Mead <amead2 at alanmead.org> wrote:

> Dean Serenevy wrote:
> > On 05/17/2010 05:25 PM, Alan Mead wrote:
> >   
> >> Assuming that shuffle() is not the culprit, I think it's just that when
> >>     
> >
> > Bad assumption. That is not the Fisher-Yates shuffle. Try this (from perlfaq):
> >
> > sub shuffle {
> >   my $n = @_;
> >   while (--$n) {
> >     my $j = int rand ($n+1);
> >     @_[$n,$j] = @_[$j,$n];
> >   }
> > }
> >
> >   
> 
> Under light testing, this seems much better.  Thanks!

sub shuffle
{
    map { splice @_, rand @_, 1 } ( 1 .. @_ )
}


-- 
Steven Lembark                                            85-09 90th St.
Workhorse Computing                                 Woodhaven, NY, 11421
lembark at wrkhors.com                                      +1 888 359 3508


More information about the Chicago-talk mailing list