Jump to content

Recommended Posts

I have a program that runs like the lottery's  powerball game, i was wondering if anyone could explain how a "Quick Pick" option would be implemented.

 

<html>
<head>
     <h1 style="text-align:center;font-family:arial;color:green;">PowerBall</h1>
</head>
<body>
     <h2 style="text-align:center;font-family:arial;color:coral;">Lottery Ticket</h2>
 <h3 style="text-align:center;">
     <?php

        $intGrandPize = 10000000;
         $intRegCount = 5;
         $intMaxReg = 59;
         $intMaxPB = 49;




	// if (isset($_POST['quickP'])){
	 //$quick_pick = array_slice($numberRange, 0, 6);}
	 //$numberRange = range(1, $intMaxReg);
	 //shuffle($numberRange);

        if (count($_POST)>0)  {
             $aryPick = array();
             $intPower = 0;
             for($t=1;$t<=$intRegCount;$t++) {
                 if (isset($_POST['num'.$t])) {
                     $intPick = (int)$_POST['num'.$t];
                     if ($intPick > 0 && $intPick <= $intMaxReg && !in_array($intPick,$aryPick)) {
                         $aryPick[] = $intPick;
                     }
                 }
             }
             if (isset($_POST['Power']) && (int)$_POST['Power'] > 0 && $_POST['Power'] <= $intMaxPB) {
                 $intPower = (int)$_POST['Power'];
             }
             if (count($aryPick) < 5 || $intPower == 0) {
                 echo "<font color='red'>'*Five unique numbers and a PowerBall selection are Required*'</font>";;
             }
             else {
                 // Have valid numbers...

                sort($aryPick); // For if you are going to display them, they will be in order...

                // Pick your winners

                $aryAllBalls = range(1,$intMaxReg); // array of numbers 1 - 59
                 shuffle($aryAllBalls); // Randomize their order
                 $aryAllBalls = array_chunk($aryAllBalls,$intRegCount); 
                // The above breaks up into an array with 5 numbers each
                 // [0] contains the first 5 balls of all balls randomized, these are what are "picked"
                 $aryPickedBalls = $aryAllBalls[0]; 
                sort($aryPickedBalls); // Sort them for display

                $intPowerBall = rand(1,$intMaxPB);

                echo "YOUR WINNING NUMBERS ARE: <br>",implode('   ',$aryPickedBalls),'   PB: ',$intPowerBall,"<br>\n<br>\n";

                echo "You Picked: ";
                 foreach($aryPick as $key=>$val) {
                     if (in_array($val,$aryPickedBalls)) {
                         echo '<strong>',$val,'</strong> ';
                     }
                     else {
                         echo $val,' ';
                         unset($aryPick[$key]); // Remove it since it didn't match
                     }
                 }
                 $bMatchPB = ($intPower == $intPowerBall); // Set here since checked in 3 places...
                 if ($bMatchPB) {
                     echo 'PB: <strong>',$intPower,"</strong><br>\n<br>\n";
                 }
                 else {
                     echo 'PB: '.$intPower,"<br>\n<br>\n";
                 }

                // At this point, $aryPick will only contain matching numbers...
                 $intMatches = count($aryPick);
                 echo 'You matched '.$intMatches,' numbers and did ';
                 if (!$bMatchPB) { echo 'not '; }
                 echo "match the PowerBall number.<br><br>\n\n";

                // HERE YOU WOULD DO SOMETHING TO SAY HOW MUCH THEY WON
                 if ($intMatches>=3 || $bMatchPB) {
                     $intWinnings = 0;
                     switch ($intMatches) {
                         case 0:
                                 if ($bMatchPB) { $intWinnings = 3; }
                                 break;
                         case 1:
                                 if ($bMatchPB) { $intWinnings = 4; }
                                 break;
                         case 2:
                                 if ($bMatchPB) { $intWinnings = 7; }
                                 break;
                         case 3:
                                 if ($bMatchPB) {
                                     $intWinnings = 100;
                                 } else {
                                     $intWinnings = 7;
                                 }
                                 break;
                         case 4:
                                 if ($bMatchPB) {
                                     $intWinnings = 10000;
                                 } else {
                                     $intWinnings = 100;
                                 }
                                 break;
                         case 5:
                                 if ($bMatchPB) {
                                 $intWinnings = $intGrandPize;
                                 } else {
                                     $intWinnings = 200000;
                                 }
                                 break;
                         default:
                                 echo "ERROR: Winning Combination not defined in systen!!!<br>\n";
                     }
                     echo "<strong>YOU ARE A WINNER!!!!</strong><br>\n";
                     echo 'You Won: $'.number_format($intWinnings,0),"<br>\n";
                 }
                 else {
                     echo "Sorry, you didn't win. Try again!<br>\n";
                 }
             } // END: if (had valid numbers picked)
         } // END: There was data posted (ie. Form submitted)
     ?>
     <hr>
     <p>Pick 5 unique numbers!!</p>
     <form action="" method="post">
         <?php for($t=1;$t<=$intRegCount;$t++): ?>
             <select name="num<?php echo $t; ?>">
                 <option value="0">Pick</option>
                 <?php for($n=1;$n<=$intMaxReg;$n++): ?>
                     <?php if (isset($_POST['num'.$t]) && $_POST['num'.$t]==$n): ?>
                         <option selected="selected" value="<?php echo $n; ?>"><?php echo $n; ?></option>
                     <?php else: ?>
                         <option value="<?php echo $n; ?>"><?php echo $n; ?></option>
                     <?php endif; ?>
                 <?php endfor; ?>
             </select>
         <?php endfor; ?>
         PB
         <select name="Power">
             <option value="0">Pick</option>
             <?php for($n=1;$n<=$intMaxPB;$n++): ?>
                 <?php if (isset($_POST['Power']) && $_POST['Power']==$n): ?>
                     <option selected="selected" value="<?php echo $n; ?>"><?php echo $n; ?></option>
                 <?php else: ?>
                     <option value="<?php echo $n; ?>"><?php echo $n; ?></option>
                 <?php endif; ?>
             <?php endfor; ?>
         </select>
	 <br><br>
         <input type="submit" name="submit" value="PLAY THESE NUMBERS!">
	 <p> OR</p>

	 <input type="submit" name="quickP"  value="Quick Pick">

	 <p> *Randomly Generates numbers </p>
         

     </form>
     </h3>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/250840-random-numbers/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.