in reply to Picking unique element in random from a array
(updated to fix a minor problem). Or, if wanting to produce a new array of the results:my $limit = 0; for $selection ( sort { rand() <=> 0.5 } @array ) { print "$selection\n"; ( ++$limit < 10 ) or last; }
@output = sort { rand() <=> 0.5 } @input; $#output = 9; #truncate the randomly sorted copy
-M
Free your mind
|
|---|