Monte Carlo Calculation of pi in JavaScript


pi<<algorithm

<!DOCTYPE html>
<html>
<body>
<script>
var n = prompt("n:", "");
k = 0;
for(i = 1; i <= n; i++){
    x = Math.random();
    y = Math.random();
    if ((x * x + y * y) <= 1) k++;    
}
p = 4 * k / n;
alert('pi = ' + p);
</script> 
</body>
</html>

loadposition Spis-mod_AJS}