Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

A bad shuffle

by tlm (Prior)
on Mar 20, 2005 at 21:05 UTC ( [id://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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-29 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found