in reply to Re: Picking unique element in random from a array
in thread Picking unique element in random from a array
Shuffling all 100 elements (or indices) just to get 10 of them... A partial Fisher-Yates shuffle can be more efficient. For example, using pickFromRange which I wrote after Limbic~Region asked for such a thing in the CB (probably prompted by this thread), you could do:
my @pick= @quest[ pickFromRange( 10, 0, $#quest ) ];
Though I bet it will actually be slower than just shuffling the whole list of indices for this particular case given how slow dispatching Perl opnodes is and that List::Util uses XS. But for larger lists, it could be a win.
- tye
|
|---|