Advertisement
ZaynerTech

Binomial Probabilities

Mar 7th, 2013
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.66 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. #
  4. #
  5. # Usage: ./binom.pl <number of trials> <number of times to repeat>
  6. #
  7.  
  8. $total = 0;
  9. for($y = 0; $y < $ARGV[1]; $y++)
  10. {
  11. $val = 0;
  12. $guess = 0;
  13. $winner = 0;
  14. for($x = 0; $x < $ARGV[0]; $x++)
  15. {
  16.   #10 possible outcomes = p=0.1
  17.   #because of int this isn't 11
  18.   $val = int(rand(10));
  19.   $guess = int(rand(10));
  20.   #print "Val: $val Guess: $guess\n";
  21.   if($val == $guess){ $winner++; }
  22.   $tots++;
  23. }
  24. $percent = $winner/$x;
  25. #print "Win: $winner : $percent\n";
  26. $total = $winner + $total;
  27.  
  28. #Are we greater than the expected 10%?
  29. if($percent > 0.1){ $wins = $wins + 1; }
  30. }
  31. $percent = $wins / ($ARGV[1]);
  32. print "Winner: $wins : $percent\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement