Advertisement
Guest User

Untitled

a guest
May 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?
  2. ini_set('memory_limit','1000M');
  3. $n = 100000;
  4.  
  5. $children = array();
  6. for($i = 0; $i<$n; $i++)
  7. {
  8.   $children[$i]['f'] = array('sex' => rand(0,1),'day' => rand(0,6));
  9.   $children[$i]['s'] = array('sex' => rand(0,1),'day' => rand(0,6));
  10. }
  11.  
  12. foreach($children as $i => $child)
  13. {
  14.   if( ($child['f']['sex'] == 0 && $child['f']['day'] == 0) || ( $child['s']['sex'] == 0 && $child['s']['day'] == 0))
  15.   {
  16.     $condition[] = $child;
  17.   }
  18. }
  19. echo "n: $n, sample size: ".count($condition)."\n";
  20. foreach($condition as $child)
  21. {
  22.   if($child['f']['sex'] == 0 && $child['s']['sex'] == 0)
  23.   {
  24.     $both++;
  25.   }
  26. }
  27. echo "both boys: $both\n";
  28. echo "pct: ".$both/count($condition)."\n";
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement