Guest User

Untitled

a guest
Nov 4th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.30 KB | None | 0 0
  1. <?php
  2.  
  3. $twoHeads = 0;
  4. $total = 0;
  5. for($i = 0; $i < 1000000; ++$i) {
  6.     $coinOneHeads = mt_rand(0, 1);
  7.     $coinTwoHeads = mt_rand(0, 1);
  8.  
  9.     if( !$coinOneHeads && !$coinTwoHeads ) {
  10.         continue;
  11.     }
  12.  
  13.     ++$total;
  14.     if( $coinOneHeads && $coinTwoHeads ) {
  15.         ++$twoHeads;
  16.     }
  17. }
  18.  
  19. echo $twoHeads / $total;
Advertisement
Add Comment
Please, Sign In to add comment