in reply to Picking unique element in random from a array
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Picking unique element in random from a array
by Limbic~Region (Chancellor) on Aug 09, 2006 at 12:59 UTC | |
|
Re^2: Picking unique element in random from a array (partial)
by tye (Sage) on Aug 09, 2006 at 16:50 UTC |