Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use POSIX;
- my $numRuns = 100000;
- my $rangeMax = 100;
- my $numPicks = 25;
- my $countTies = 0;
- for (my $run = 0; $run < $numRuns; $run++) {
- my @picks;
- #print "Run " . ($run+1) . ": ";
- for (my $pick = 0; $pick < $numPicks; $pick++) {
- #push a new value onto the list, make it an int for viewability's sake
- push @picks, ceil(rand($rangeMax));
- }
- @picks = sort {$a < $b} @picks;
- #print "@picks\n";
- if ($picks[0] == $picks[1]) {$countTies++;}
- }
- print "Number of ties: $countTies\n";
- my $result = $countTies/$numRuns;
- print "Result: $result\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement