http://qs321.pair.com?node_id=1145218


in reply to Perl - Unique Numbers

Welcome deelinux

And another way of doing what you need:

use strict; use warnings; my $x = 1; my $y = 20; my $looptimes = 10; my %NoDups = (); while( 1 ) { my $num = int( 1 + rand( 19 ) ); if ( exists $NoDups{ $num } ) { next; } $NoDups{ $num } = 1; if ( keys %NoDups >= $looptimes ) { last; } } foreach my $no ( sort {$a<=>$b} keys %NoDups ) { print "$no\n"; }

Good Luck...Ed

"Well done is better than well said." - Benjamin Franklin