#!/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, try again next; } # end if push (@picks, $num); # add new number to list $count -- ; # decrement count and get another number } # 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;