UNPKG

@nexys/math-ts

Version:

[![npm version](https://badge.fury.io/js/%40nexys%2Fmath-ts.svg)](https://www.npmjs.com/package/@nexys/math-ts) [![TavisCI](https://travis-ci.com/Nexysweb/tableau-wdc-react.svg?branch=master)](https://travis-ci.com/github/Nexysweb/math-ts) [![Deployment](

18 lines (17 loc) 440 B
"use strict"; 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; };