On Tue, Jul 31, 2001 at 06:32:15PM -0500, CDitty wrote:
: In both my perl books.  Learning Perl(O'Reilly) and Perl 5 Interactive 
: Course(Waite Group).
: 
: The shuffle routine in not listed in either of these books, although they 
: are almost 1 year old.   When I try and use shuffle I get
: Undefined subroutine &main::shuffle  and my program stops.

Did you read the documentation provided by executing 'perldoc -q
shuffle'?

If you did, you noticed a subroutine in the coding example that
shuffles an array with the fisher-yates algorithm.  I'll post it here
so everyone can see it

       Use this:

           # fisher_yates_shuffle( \@array ) :
           # generate a random permutation of @array in place
           sub fisher_yates_shuffle {
               my $array = shift;
               my $i;
               for ($i = @$array; --$i; ) {
                   my $j = int rand ($i+1);
                   next if $i == $j;
                   @$array[$i,$j] = @$array[$j,$i];
               }
           }

           fisher_yates_shuffle( \@array );    # permutes @array in place

There is another example in that FAQ question which was posted here by
Micheal Fowler, whose name I surely misspelled.  :-)


  Casey West

-- 
Shooting yourself in the foot with Fortran 
You shoot yourself in each toe, iteratively, until you run out of
toes; then you shoot the sixth bullet anyway since no exception
processing was anticipated. 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to