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