The technique is as follows Take a random point P at coordinate X Y such that 0 x 1 and 0 y 1 If x2 y2 1 then the point is inside the quarter disk of radius 1 otherwise the point is outside let iterations 10000 let insideCount 0 for let i 0 i iterations i let x Math random let y Math random if Math pow x 2 Math pow y 2 1 insideCount let approximateValueOfPi 4 insideCount iterations console log approximateValueOfPi approximateValueOfPi
i 0 i iterations i let x Math random let y Math random if Math pow x 2 Math pow y 2 1 insideCount let approximateValueOfPi 4 insideCount iterations console log approximateValueOfPi approximateValueOfPi