Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Monte Carlo approximation of PI

by YuckFoo (Abbot)
on Apr 04, 2003 at 18:00 UTC ( [id://248151]=note: print w/replies, xml ) Need Help??


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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://248151]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found