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 int (1 + rand 49), " ", for 1..6' 48 16 40 39 21 24
$ 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:
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 1 + int rand 49, ' ', for 1..6"
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.$ perl -e 'print int (1 + rand 49), " ", for 1..6' 20 32 37 32 3 39
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |