or... perl -le '@l=sort{rand$_<=>rand$_}(1..10);print for@l[0..2]]' | [reply] [d/l] |
#!/usr/bin/perl
use strict;
use warnings;
no warnings qw /syntax/;
my @array = (1 .. 4);
my %count;
my $mult = 10_000;
for (1 .. 24 * $mult) {
my @t = sort {rand 1 <=> rand 1} @array;
$count {"@t"} ++;
}
foreach my $key (sort keys %count) {
printf "%5d: %s\n" => $count {$key}, $key
}
__END__
15063: 1 2 3 4
15069: 1 2 4 3
7419: 1 3 2 4
7615: 1 3 4 2
7602: 1 4 2 3
7606: 1 4 3 2
14978: 2 1 3 4
14923: 2 1 4 3
7497: 2 3 1 4
7460: 2 3 4 1
7558: 2 4 1 3
7401: 2 4 3 1
7485: 3 1 2 4
7484: 3 1 4 2
7585: 3 2 1 4
7577: 3 2 4 1
14876: 3 4 1 2
14968: 3 4 2 1
7467: 4 1 2 3
7544: 4 1 3 2
7461: 4 2 1 3
7477: 4 2 3 1
14853: 4 3 1 2
15032: 4 3 2 1
Abigail | [reply] [d/l] [select] |
When golfing... (I did not really care about old perl compatibility)
A quick trip to the sort perldoc exposes me to:
The comparison function is required to behave. If it returns
inconsistent results (sometimes saying $x[1] is less than $x[2]
and sometimes saying the opposite, for example) the results are
not well-defined.
So i guess my golf does not produce completely random picks thanks for the heads up... ohh well =) | [reply] [d/l] |