0

Im flipping 2 coins 100 times in a while loop and want to know how many times i hit: Tails, Tails, or Head,Tails, or Head, Head.

20th Dec 2016, 9:04 AM
Luuk Hazes
Luuk Hazes - avatar
7 odpowiedzi
+ 2
<html> <head> <title>Coins</title> </head> <body> <?php $heads = $tails = $both = 0; for ($i = 0; i < 100; i+=1) { $coin1 = rand(0, 1); $coin2 = rand(0, 1); if ($coin1 & $coin2) $heads += 1; if (!($coin1 & $coin2)) $tails += 1; else $both+=1; } echo("Heads: $heads"); echo("Tails: $tails"); echo("Both: $both"); ?> </body> </html>
20th Dec 2016, 9:20 AM
Gabe Rust
Gabe Rust - avatar
+ 2
This is wrong. let me fix it
20th Dec 2016, 9:51 AM
Gabe Rust
Gabe Rust - avatar
+ 1
Yeah I'm a bit "rusty" on PHP 😂
20th Dec 2016, 9:55 AM
Gabe Rust
Gabe Rust - avatar
0
Thanks a lot!
20th Dec 2016, 9:51 AM
Luuk Hazes
Luuk Hazes - avatar
0
I noticed, but it worked, although I wanted to know specifically how many: Tails,Tails. Heads,Heads and tail,head/head,tail there are.
20th Dec 2016, 9:54 AM
Luuk Hazes
Luuk Hazes - avatar
0
I'm a noob :V, just could not figure out how to count all the possibilities, managed to flip all the coins though.
20th Dec 2016, 9:56 AM
Luuk Hazes
Luuk Hazes - avatar
0
I am also having trouble with the coin toss
19th Sep 2020, 7:25 PM
Goodzone Lo
Goodzone Lo - avatar