Advertisement
saikrishnadeep

Inefficiency of mt_reand() in PHP

Dec 16th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. <?php
  2. ////
  3. function flip($h, $t, $times) {
  4. if ($h + $t <= $times) {
  5. $a = mt_rand(0, 1);
  6. if ($a == 1) {
  7. return flip($h + 1, $t, $times);
  8. } else {
  9. return flip($h, $t + 1, $times);
  10. }
  11. } else {
  12. return $h . ',' . $t;
  13. }
  14. }
  15. /////
  16. function trial($l) {
  17. $ar = array(
  18. 'null'
  19. );
  20. for ($i = 1; $i <= $l; $i++) {
  21. array_push($ar, flip(0, 0, 29));
  22. }
  23. $countAr = array_count_values($ar);
  24. arsort($countAr);
  25. foreach ($countAr as $key => $value) {
  26. print "<b>$key</b>" . ": " . $value . "</br>";
  27. }
  28. }
  29. trail(500);
  30. ?>
  31.  
  32.  
  33. www.saikrishnadeep.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement