Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gcd($a,$b) {
- while($a > 0 && $b > 0) {
- if($a > $b)
- $a %= $b;
- else
- $b %= $a;
- }
- return $a + $b;
- }
- function pi_calc($n) {
- $m = 0;
- for($i = 1; $i <= $n; $i++) {
- $a = mt_rand();
- $b = mt_rand();
- if (gcd($a,$b) == 1) $m++;
- }
- return sqrt((6 * $n) / $m);
- }
- echo pi_calc(1000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement