#!/usr/bin/perl -w use strict; use List::Util qw(shuffle); ## CSV file has following format: ## Game Name, Month, Day, Year, Num1, Num2, Num3, Num4, Num5, Mega Bal +l, Megaplier ## The Megaplier is ignored open(FILE,"megamillion.csv") or die "Cannot open csv: $!\n"; my @csv = <FILE>; close(FILE); ## Initialize the temporary hashes my %hash; my %bonus; ## Inefficient loop to get number counts foreach my $line (@csv) { my ($game,$month,$day,$year,$one,$two,$three,$four,$five,$bonu +s) = split(/,/,$line); $hash{$one}++; $hash{$two}++; $hash{$three}++; $hash{$four}++; $hash{$five}++; $bonus{$bonus}++; } ## Initialize the weighted arrays my @draw; my @mega; ## Loop and push the numbers into the arrays, and shuffle foreach my $key (sort keys %hash) { for(my $count = 0; $count < $hash{$key}; $count++) { push(@draw,$key); } } @draw = shuffle(@draw); foreach my $key (sort keys %bonus) { for(my $count = 0; $count< $hash{$key}; $count++) { push(@mega,$key); } } @mega = shuffle(@mega); sub draw_regular { $draw[ rand(@draw) ]; } sub draw_mega { $mega[ rand(@mega) ]; } ## Keep track of number's we've picked my @picked; ## Loop and draw 5 numbers, pick another incase we draw the same numbe +r twice. for(my $i=0;$i<=4;$i++) { my $number = draw_regular(); foreach my $pick (@picked) { while($number == $pick) { $number = draw_regular(); } } push(@picked,$number); } ## Output the Numbers we drew. print "Draw: " . join(',', sort(@picked)) . "\n"; print "Bonus: " . draw_mega();

In reply to Lottery Numbers by OverlordQ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.