in reply to Perl - Unique Numbers

Heh, the algorithmically optimal (IMHO) way to get N unique numbers from a set of M of them is not actually covered in any of the replies. Not that this means you shouldn't use any of those solutions. I just think the method should be mentioned.

The process is the same as that used in List::Util's shuffle(), the Fisher-Yates Shuffle, except you stop early.

sub tenOf20 { my @set = 1..20; for( 0..9 ) { my $r = $_ + int( rand(@set-$_) ); @set[$_,$r] = @set[$r,$_] if $r != $_; } return @set[0..9]; }

- tye