Here is the indented code. Just stripping down to the one simple for loop doesn't help because it will just print a number 1-12, 100 times. That won't really allow me to observe any sort of pattern or inconsistencies, while the output with all of the other code thrown in there gives values like xx.xx, which can range from negative hundreds of dollars to positive hundreds of dollars.
#!/usr/bin/perl use Math::Random; use DBI; use strict; $username = "username"; $password = "password"; $database = "database"; $dbh = DBI->connect("DBI:mysql:$database", $username, $password); for($k=1;$k<=100;$k++) { $netwinnings = 0; $counttwos = 0; for($i=1;$i<=100;$i++) { $winnings = 0; $gameover = 0; $numrolls = 0; while($gameover == 0) { $numrolls++; ##if($numrolls == 2) { print "THE POINT IS $roll\n"; } $roll = rolldice(); ##print "ROLL #$numrolls $roll\n"; if($numrolls == 1) { $point = $roll; if($roll == 7 || $roll == 11) { $gameover = 1; $winnings += 1; ##print "WIN $winnings\n\n"; } elsif($roll == 2 || $roll == 3 || $roll == 12) { $gameover = 1; $winnings -= 1; ##print "LOSE $winnings\n\n"; } } else { if($roll == $point) { $gameover = 1; if($roll == 6 || $roll == 8) { $gameover = 1; $winnings += 1.2 + 1; ##print "WIN $winnings\n\n"; } elsif($roll == 5 || $roll == 9) { $gameover = 1; $winnings += 1.5 + 1; ##print "WIN $winnings\n\n"; } elsif($roll == 4 || $roll == 10) { $gameover = 1; $winnings += 2 + 1; ##print "WIN $winnings\n\n"; } } elsif($roll == 7) { $gameover = 1; $winnings -= 2; ##print "LOSE $winnings\n\n"; } } } $winnings = sprintf "%.2f", $winnings; $netwinnings += $winnings; $netwinnings = sprintf "%.2f", $netwinnings; } $sth = $dbh->prepare("SELECT value,qty FROM craps WHERE value = $n +etwinnings"); $sth->execute(); ($value,$qty) = $sth->fetchrow_array(); ##print "\n\n$value - $netwinnings\n\n"; if($value == $netwinnings) { $sth = $dbh->prepare("UPDATE craps SET qty = qty + 1 WHERE val +ue = $netwinnings"); $sth->execute(); } else { $sth = $dbh->prepare("INSERT INTO craps VALUES($netwinnings,1) +"); $sth->execute(); } print "NET WIN $netwinnings\n"; } $dbh->disconnect; sub rolldice() { $d1 = random_uniform_integer(1,1,6); $d2 = random_uniform_integer(1,1,6); $roll = $d1 + $d2; return $roll; }

In reply to Re: Re: check my logic & a random number issue by rmckillen
in thread check my logic & a random number issue by rmckillen

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.