Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

A bad shuffle

by tlm (Prior)
on Mar 20, 2005 at 21:05 UTC ( #441060=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub naive_shuffle {
      my $n = my @p = @_;
    ...
      }
      return @p;
    }
    
  2. or download this
    # untested
    sub naive_shuffle_rec {
    ...
      @p[ $i, $j ] = @p[ $j, $i ]; # swap
      return ++$i < $n ? naive_shuffle_rec( $i, @p ) : @p;
    }
    
  3. or download this
    sub naive_shuffle_traverse {
      my $i = shift;
    ...
        return;
      }
    }
    
  4. or download this
    naive_shuffle_traverse(-1, undef, 1..3);
    
  5. or download this
    sub naive_shuffle_count {
      my $i = shift;
    ...
        return;
      }
    }
    
  6. or download this
    my %tally = ();
    naive_shuffle_count( -1, undef, \%tally, 1..3 );
    
  7. or download this
      DB<2> x \%tally
    0  HASH(0x82d7f94)
    ...
       '2 3 1' => 5
       '3 1 2' => 4
       '3 2 1' => 4
    
  8. or download this
    sub random_perm {
      my $n = my @p = @_;
    ...
      }
      return @p;
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://441060]
Approved by Joost
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-07-04 09:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls