News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Tobias Schlitt's Blog:
Randomized Pi calculation
April 02, 2007 @ 10:04:00

Since there is no "magic variable" to get a value for Pi in an application, Tobias Schlitt offers up the next best thing - his homegrown solution for creating the value (using a randomized variation).

I don't know which is the most common way to calculate Pi in computer programs, but from the stochastics book a read for my recent stochastics exam, I have a randomized variation, which is quite cool I think.

The code example is included along with a bit of explanation for those not familiar with the concepts behind it. It uses two of PHP functions, pow() and mt_rand(), to run through a series of iterations and, using a preset precision value, find the "hits" to finally calculate the value at the end.

1 comment voice your opinion now!
randomize pi calculation pow mtrand precision randomize pi calculation pow mtrand precision


blog comments powered by Disqus

Similar Posts

Syntux Blog: Advanced Caching Technique - Block Randomization

Suspekt Blog: mt_srand and not so random numbers

Tobias Schlitt's Blog: Randomized Pi calculation

Pádraic Brady: Predicting Random Numbers In PHP - Itís Easier Than You Think!

Openwall.com: php_mt_seed went beyond PoC (mt_rand seed cracker)


Community Events





Don't see your event here?
Let us know!


update language framework opinion library api package community release zendserver deployment laravel interview bugfix introduction series version podcast unittest symfony

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework