Guest User

Untitled

a guest
May 26th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: francesco
  5. * Date: 21/05/2018
  6. * Time: 22:42
  7. */
  8.  
  9.  
  10. $hit = 0;
  11. $limit = (int) drush_get_option("limit", 20);
  12. $attempts = (int) drush_get_option("attempts", 50000);
  13.  
  14. if ($limit < 1 || $limit > 100) {
  15. echo "limit must be between 1 and 100\n";
  16. return;
  17. }
  18. echo "Attempts are $attempts\n";
  19. echo "Limit is $limit%\n";
  20. for ($i = 1; $i <= $attempts; $i++) {
  21. $hit = $hit + (rand(1, 100) <= $limit ? 1 : 0);
  22. echo $i . " attempts processed so far.... (temp hit ratio is " . ($hit / $i) * 100 . "%) \r";
  23. }
  24. echo "\n";
  25. echo "Final hit ratio is was " . ($hit / $attempts) * 100 . "%\n";
  26.  
  27. /*
  28. OUTPUT IS SOMETHING SIMILAR TO THIS:
  29.  
  30. Attempts are 100000
  31. Limit is 30%
  32. 100000 attempts processed so far.... (temp hit ratio is 30.258%)
  33.  
  34. Final hit ratio is was 30.258%
  35. */
Add Comment
Please, Sign In to add comment