@nexys/math-ts
Version:
[](https://www.npmjs.com/package/@nexys/math-ts) [](https://travis-ci.com/github/Nexysweb/math-ts) [ • 440 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.montecarlo = (n) => {
if (n < 1) {
throw Error(`n miust be great than zero`);
}
let z = 0;
for (let i = 0; i < n; i++) {
const x = Math.random();
const y = Math.random();
const r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
if (r < 1) {
z += 1;
}
}
return 4 / n * z;
};