in reply to random pairs
Perhaps the following will do what you need:
use Modern::Perl; my ( %pairsHash, $randVal ); for ( 0 .. 9 ) { do { $randVal = int( rand(100) ) } while ( ( exists $pairsHash{$randVal} and $pairsHash{$randVal} = += $_ ) or $randVal == $_ ); $pairsHash{$_} = $randVal; } say "($_, $pairsHash{$_})" for sort { $a <=> $b } keys %pairsHash;
Sample output for 10 pairs:
(0, 82) (1, 50) (2, 6) (3, 72) (4, 67) (5, 71) (6, 40) (7, 93) (8, 2) (9, 22)
The script creates unique sets of two different numbers, where the second number (0 - 99) can be repeated.
Hope this helps!
|
|---|