$aantal=100000; for ($i=1;$i<=$aantal;$i++){ $x = rand(); $y = rand(); # print "$i:($x,$y)\n"; $r=$x*$x+$y*$y; if ($r < 1) {$k++;} } print "pi = ".$k*4/$aantal;
$aantal=100000; for ($i=1;$i<=$aantal;$i++){ $x = rand(); $y = rand(); # print "$i:($x,$y)\n"; $r=$x*$x+$y*$y; if ($r < 1) {$k++;} } print "pi = ".$k*4/$aantal;
You must be logged in to post a comment.