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; }
In reply to Re: random number generation.
by ikegami
in thread random number generation.
by newbio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |