This is an easy way to get six random integer numbers between 1 and 49:
$ perl -e 'print int (1 + rand 49), " ", for 1..6' 48 16 40 39 21 24
Adding 1 to the result of the rand function makes it sure that the obtained integers will be between 1 and 49 (and not between 0 and 48). It can even be made slightly simpler:
$ perl -e 'print 1 + int rand 49, " ", for 1..6' 5 33 19 21 25 39

If you are under Windows, change quotes for apostrophes and vice-versa:

perl -e "print 1 + int rand 49, ' ', for 1..6"
However, besides everything that has already been said, this still suffers from a major drawback if you're going to use it for picking up lotto numbers: there is no guarantee that you don't get twice the same number. I only had to run the first Perl one-liner above 9 times to get the following result:
$ perl -e 'print int (1 + rand 49), " ", for 1..6' 20 32 37 32 3 39
where number 32 appears twice, which is not good for lotto numbers. Since this looks a bit like a homework assignment, I'll leave it to you to find out how to make an additional draw if you find a number that has already been picked up.

A final additional advice: don't comment out use strict;, rather solve the problems that it diagnoses (hint: use my to declare your variables).


In reply to Re: Where is the zero coming from? by Laurent_R
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.