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;
    }