in reply to
random pairs
Without retries
use strict;
use warnings;
my %pairs;
my @left = (0,1,2,5,7,8,10); #put your own predetermined numbers
foreach my $val1 (@left){
my @right = ();
foreach my $val2 (0..99){
push(@right, $val2) if $val1 != $val2 && (!exists $pairs{$val2} ||
+ $pairs{$val2} != $val1);
}
$pairs{$val1} = $right[int(rand($#right+1))];
}
foreach(@left){
print $_, ',', $pairs{$_}, ' ';
}
Update: modified condition so that it works correctly when there's a zero in the predetermined numbers. Also clean under 'use warnings;' now.