Hello Chuma,
The core module List::Util has a shuffle function which does what you want:
use strict; use warnings; use Const::Fast; use Data::Dump; use List::Util qw( shuffle ); const my $N => 10; const my $K => 5; my @range = (shuffle 1 .. $N)[0 .. $K - 1]; dd \@range;
Sample output:
23:04 >perl 2029_SoPW.pl [10, 9, 5, 6, 7] 23:04 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Pick k numbers at random
by Athanasius
in thread Pick k numbers at random
by Chuma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |