function coingame() { for ($i = 1; $i <= 5000; $i++) { $coin = rand(0, 1); if ($coin == 0) { $head++; } elseif ($coin == 1) { $tails++; } echo "Attempt #" . $i . ": Throwing a coin... It's a "; heads_tails($coin); echo " Got " . $head . "head(s) so far and " . $tails . "tail(s) so far.<br>"; } }
* Released under the MIT license. See the file LICENSE * for the complete license */ $dice6 = rand(1, 6); $dice20 = rand(1, 20); $coin = rand(1, 2); $rps = rand(1, 3); function heads_tails() { if ($coin == 1) { return "You got heads."; } else { return "You got tails."; } } $ht_var = heads_tails(); function rock_paper_scissors() { if ($rps == 1) { return "You got rock."; } elseif ($rps == 2) { return "You got paper."; } else { return "You got scissors."; } } $rps_var = rock_paper_scissors(); function the_ask() { ask("Welcome to the chance facilitator. Select 1 for six sided dice, 2 for twenty sided dice, 3 for a coin flip, 4 for rock paper scissors.", array("choices" => "1(one, 1), 2(two, 2), 3(three, 3), 4(four, 4)", "timeout" => 60.0, "attempts" => 3, "onChoice" => "choiceFCN", "onBadChoice" => "badChoiceFCN")); }