in reply to Some help with a lottery picking program

I've taken a few shortcuts for you, and added a check to be sure you don't get more than one occurrence of any number in a line.
$| = 1; print qq( ------------------------------------------------------- National Lottery Number Picker ------------------------------------------------------- How many lines do you want to play? ); my $num_lines = <STDIN>; $num_lines =~ s/\D+//g; die "Good. Don't waste your money!\n" unless $num_lines; my @numbers = (1..49); my $output; for (1..$num_lines) { my @line = (); my %chosen = (); for (1..6) { my $element; while (!$element || $chosen{$element}) { $element = $numbers[rand @numbers]; } push @line, $element; $chosen{$element} = 1; } $output .= join "\t", sort {$a <=> $b} @line; $output .= "\n"; } print $output; # Then, do your e-mail thing. Send $output as the message

Replies are listed 'Best First'.
srand
by joealba (Hermit) on Nov 04, 2001 at 01:55 UTC
    And BTW, srand is called implicitly at your first use of rand, as long as you're using perl 5.004 or greater. perldoc srand