Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #
- #
- #
- # Usage: ./binom.pl <number of trials> <number of times to repeat>
- #
- $total = 0;
- for($y = 0; $y < $ARGV[1]; $y++)
- {
- $val = 0;
- $guess = 0;
- $winner = 0;
- for($x = 0; $x < $ARGV[0]; $x++)
- {
- #10 possible outcomes = p=0.1
- #because of int this isn't 11
- $val = int(rand(10));
- $guess = int(rand(10));
- #print "Val: $val Guess: $guess\n";
- if($val == $guess){ $winner++; }
- $tots++;
- }
- $percent = $winner/$x;
- #print "Win: $winner : $percent\n";
- $total = $winner + $total;
- #Are we greater than the expected 10%?
- if($percent > 0.1){ $wins = $wins + 1; }
- }
- $percent = $wins / ($ARGV[1]);
- print "Winner: $wins : $percent\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement