Hi all. I have a little program here that generates a lottery play slip for the mega-millions game. It selects 50 of the 52 numbers exactly once over 10 tickets of 5 numbers each. It then selects 10 super ball numbers, one for each ticket. It then prints it all out(duh).
I wonder if anyone would like to poke fun at my code. I'm kinda new at this so I'm sure there's a lot done wrong. For starters, the 'use strict;' and 'use warnings;' lines do not like my code at all(not sure why), and I'm sure this program is much longer than it needs to be. Some statistical info: The plan here is to hit all, or nearly all(50/52ths) of the numbers on ten tickets. The trick, then is to hit three or more numbers on any one ticket. The chances of hitting with this method are, like 2 in 2.5 million instead of 1 in 2.5 million. Still ridiculous but more fun. There is no odds gain in selecting the super ball numbers, unless it is that you are guaranteed to select ten different super ball numbers. We can discuss the odds later if anyone is interested. The code(try not to laugh out loud): #!/usr/bin/perl #numpick.pl #use strict; #use warnings; #a program to pick lottery numbers #select 50 numbers in 10 5 number tickets #select 10 supernumbers #all numbers range from 1 to 52 #select each number only once. my $try=1; my $numbers; my $supers; my $i=1; my $j=1; my $k=1; my $l=1; my $m=1; my $n=1; #select 50 numbers while($i<51){ #generate a random number between 1 and 52 $try = int(rand(51)+.5)+1; # print "(", $try, ")"; #check to see if that number has been generated earlier $j=1; while ($j<51){ if($try != $numbers[$j]){#this is a new number $j=$j+1; } else {#we've seen this number before $try = int(rand(51)+.5)+1;#generate a new number # print "(",$try,")"; $j=1; } } $numbers[$i] = $try;#the number is good -- store it # print $i, "-"; # print $numbers[$i],"\n"; $i=$i+1; } #print "\n"; #pick ten supernumbers while($l<11){ #generate a random number between 1 and 52 $try = int(rand(51)+.5)+1; # print "(", $try, ")"; #check to see if that number has been generated earlier $m=1; while ($m<11){ if($try != $supers[$m]){#this is a new number $m=$m+1; } else {#we've seen this number before $try = int(rand(51)+.5)+1;#generate a new number # print "(",$try,")"; $m=1; } } $supers[$l] = $try;#the number is good -- store it # print $l, "-"; # print $supers[$l],"\n"; $l=$l+1;} # print "\n"; #print the numbers in a ticket format print "\n\n"; $k=0; while($k<10){ $l = 1; while ($l<6){ if($numbers[$k*5+$l]<10){print "0";} print $numbers[($k*5)+$l]," "; $l=$l+1; } print " - "; if($supers[$k+1]<10){print "0";} print $supers[$k+1]; print "\n"; $k=$k+1; } print "\n\n"; #print two sets of numbers(1 to 52) so the user can verify that there are no duplicates $n=1; while($n<53){ # print $n," "; $n=$n+1; } #print "\n\n"; $n=1; while($n<53){ # print $n," "; $n=$n+1; } #print "\n\n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>