Advertisement
Shaun_B

Lottery Number Simulator

May 20th, 2015
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Lottery number simulator - typo corrected version
  4.  * @author  Shaun B
  5.  */
  6. $lotteryNumbers = Array();
  7. $index = 0;
  8.  
  9. while( $index < 6 ){
  10.     $lotteryNumbers[$index] = (rand() % 49) + 1;
  11.  
  12.     if( $index > 0 ){
  13.         for( $i = 0; $i < $index; $i = $i + 1 ){
  14.  
  15.             while( $lotteryNumbers[$index] == $lotteryNumbers[$i] ){
  16.                 $lotteryNumbers[$index] = (rand() % 49) + 1;
  17.             }
  18.  
  19.         }
  20.     }
  21.  
  22.     $index = $index + 1;
  23. }
  24.  
  25. foreach( $lotteryNumbers as $number){
  26.     print( $number . PHP_EOL );
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement