Shuffle the array (using "shuffle" from List::Util) and take the first ten elements.
Update: Here's a non-destructive approach that uses "shuffle":
use List::Util 'shuffle'; my @arr = (1 .. 200); my @random = @arr[(shuffle 0 .. $#arr)[0 .. 9]]; print "@random\n";
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: Picking unique element in random from a array
by davorg
in thread Picking unique element in random from a array
by rsriram
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |