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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.