#!/usr/bin/perl use strict; use warnings; my $runs = 10000; my $luck = 0; for(1..$runs) { # Generate the lucky parcel my $hasxp = int(rand(3)) + 1; # Now, select one parcel from the 3 at random my $parcel = int(rand(3)) + 1; # We stick to our decision, so we don't care # what happens to the other parcels # Now, see if we were lucky: if($parcel == $hasxp) { $luck++; } } # print out the end result in percent print "You were lucky " . int($luck * 100 / $runs) . "% of the time sticking to your initial decision.\n";