Keep It Simple, Stupid | |
PerlMonks |
Select value from array w/o replacement (or destroying the array)by BioNrd (Monk) |
on Dec 03, 2007 at 01:55 UTC ( [id://654490]=perlquestion: print w/replies, xml ) | Need Help?? |
BioNrd has asked for the wisdom of the Perl Monks concerning the following question:
Monks,
I am currently pondering this conundrum. I have an array of numbers (not shown below), and I need to randomly select a value from that array (n) number of times, without replacement. I know this is possible with a splice ($ranpop = splice(@holder, int rand(@holder), 1)); but I do not want to destroy the array. I was thinking something along these lines: But I am doing something wrong, and I can not figure it out. Somewhere or something in that last loop needs to be adjusted. Any help is appreciated. -Bio
Even a blind squirrel finds a nut sometimes.
Back to
Seekers of Perl Wisdom
|
|