JSFiddle - React, Tailwind, and code Playground

by marlanga

JavaScript

var total=0;
var dentro=0;

function calcularPi(){
    var veces=5;
    var x,y;
    for (var i=0;i<veces;i++)
    {
        x=Math.random();
        y=Math.random();
        if (x*x+y*y<=1) dentro++;
    }
    total+=veces;
    var aproximacionPi=dentro/total*4;
    console.log(total, dentro, aproximacionPi);
}

setInterval(calcularPi,100);