RapidMod

PHP: Coin Toss Script

Mar 12th, 2018
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. /**
  2.      *
  3.      * Name coinToss
  4.      * @return string
  5.      * @author RapidMod.com
  6.      * @author 813.330.0522
  7.      *
  8.      */
  9. function coinToss(){
  10.         $counts = array("Heads"=>0,"Tails"=>0);
  11.         $opts = array(1=>"Heads",2=>"Tails");
  12.         $numOpts = random_int(5,12);
  13.         $optCount = 0;
  14.         $odds=array();
  15.         while ($optCount < $numOpts){
  16.             $optCount++;
  17.             $key = random_int(1,2);
  18.             $counts[$opts[$key]]++;
  19.             $odds[$optCount] = $opts[$key];
  20.         }
  21.         $selected = $key;
  22.         $key = random_int(1,$numOpts);
  23.         return $odds[$key];
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment