Pauleduc has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl # Program to pick 6 random & unique lottery numbers from a list of 49. # # # use strict; use warnings; $loop = 50; # number of picks to make while ($loop) { @choices = (1 .. 49); # list of available numbers # print "@choices \n"; # just for testing $count = 5; # number of picks less 1 @picks = (); # initialize/clear the array $num = rand(@choices); # get 1st random pick push (@picks, $num); # and load it into array while ($count) { # now get 5 more numbers $num = rand(@choices); if ($num ~~ @picks) { # if we already have this number, tr +y again next; } # end if push (@picks, $num); # add new number to list $count -- ; # decrement count and get another nu +mber } # end while $count @picks = sort { $a <=> $b } @picks; printf ("Lucky numbers: %02d %02d %02d %02d %02d %02d \n\n", @picks +); $loop -- ; # decrement counter } # end while $loop exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Where is the zero coming from?
by InfiniteSilence (Curate) on Aug 01, 2014 at 22:22 UTC | |
|
Re: Where is the zero coming from?
by Cristoforo (Curate) on Aug 01, 2014 at 23:18 UTC | |
by Pauleduc (Initiate) on Aug 01, 2014 at 23:29 UTC | |
|
Re: Where is the zero coming from?
by AnomalousMonk (Archbishop) on Aug 02, 2014 at 07:05 UTC | |
by BillKSmith (Monsignor) on Aug 02, 2014 at 14:57 UTC | |
by AnomalousMonk (Archbishop) on Aug 03, 2014 at 10:09 UTC | |
|
Re: Where is the zero coming from?
by CountZero (Bishop) on Aug 02, 2014 at 08:58 UTC | |
|
Re: Where is the zero coming from?
by AppleFritter (Vicar) on Aug 01, 2014 at 23:03 UTC | |
|
Re: Where is the zero coming from?
by Laurent_R (Canon) on Aug 02, 2014 at 14:29 UTC | |
by Pauleduc (Initiate) on Aug 02, 2014 at 20:56 UTC | |
by Laurent_R (Canon) on Aug 02, 2014 at 21:27 UTC |