in reply to random number generation.
A particularly simple approach is:
use List::Util qw( shuffle ); my @picks = (shuffle 1..15)[0..4];
For picking a few numbers from a very long list, "rerolling" duplicates is probably the most efficient:
Update: Added second method.my @picks; my %seen; for (1..5) { # Five numbers my $pick = int(rand(15000)) + 1; # in 1..15000. redo if $seen{$pick}++; push @picks, $pick; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: random number generation.
by newbio (Beadle) on Sep 11, 2007 at 18:15 UTC | |
by ikegami (Patriarch) on Sep 11, 2007 at 18:20 UTC | |
by newbio (Beadle) on Sep 11, 2007 at 18:52 UTC | |
by ikegami (Patriarch) on Sep 11, 2007 at 18:58 UTC |