And if this wasn't a homework question, the standard | kneejerk approach would be List::Util::shuffle (if: the list you're shuffling is relatively small; you don't necessarily need robust randomness, because shuffle is based on the rand functions in the libc library against which your Perl is built, and they may not be terribly random :).
c:\@Work\Perl\monks>perl -wMstrict -le "use List::Util qw(shuffle); ;; use constant N => 6; use constant LIST => (1 .. 49); use constant FMT => ' %02d' x N; ;; for my $pick (1 .. 5) { my @picks = sort { $a <=> $b } (shuffle LIST)[0 .. N-1]; printf qq{pick %2d: ${ \FMT } \n}, $pick, @picks; } " pick 1: 01 05 15 34 38 39 pick 2: 11 20 22 31 38 48 pick 3: 11 15 18 21 22 29 pick 4: 05 07 09 12 20 48 pick 5: 01 13 16 24 44 45
In reply to Re: Where is the zero coming from?
by AnomalousMonk
in thread Where is the zero coming from?
by Pauleduc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |