in reply to Monte Carlo approximation of PI

With a little modification, a 1.0 approximator:

OneFoo

#!/usr/bin/perl # Two Monte Carlo approximations of 1. Slow! use strict; use warnings; my $in = 0; my $count = @ARGV ? shift : 1000; rand () + rand () < 1 && $in ++ for 1 .. $count; printf "One equals %f\n", 2 * $in / $count; $in = 0; rand () < .5 && rand () < .5 && $in ++ for 1 .. $count; printf "Or maybe %f\n", 4 * $in / $count;