Comparing version 0.4.0 to 0.4.1
@@ -0,1 +1,11 @@ | ||
<a name="0.4.1"></a> | ||
## [0.4.1](https://github.com/mljs/random/compare/v0.4.0...v0.4.1) (2018-05-23) | ||
### Bug Fixes | ||
* **choice:** set a more fault-tolerant threshold for sanity of probabilities input ([7d39650](https://github.com/mljs/random/commit/7d39650)) | ||
<a name="0.4.0"></a> | ||
@@ -2,0 +12,0 @@ # [0.4.0](https://github.com/mljs/random/compare/v0.3.0...v0.4.0) (2018-05-23) |
@@ -0,1 +1,2 @@ | ||
const PROB_TOLERANCE = 0.00000001; | ||
function randomChoice(values, options = {}, random = Math.random) { | ||
@@ -23,4 +24,4 @@ const { size = 1, replace = false, probabilities } = options; | ||
} | ||
if (Math.abs(1 - cumSum[cumSum.length - 1]) > Number.EPSILON) { | ||
throw new Error('probabilities should sum to 1'); | ||
if (Math.abs(1 - cumSum[cumSum.length - 1]) > PROB_TOLERANCE) { | ||
throw new Error(`probabilities should sum to 1, but instead sums to ${cumSum[cumSum.length - 1]}`); | ||
} | ||
@@ -27,0 +28,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const PROB_TOLERANCE = 0.00000001; | ||
function randomChoice(values, options = {}, random = Math.random) { | ||
@@ -25,4 +26,4 @@ const { size = 1, replace = false, probabilities } = options; | ||
} | ||
if (Math.abs(1 - cumSum[cumSum.length - 1]) > Number.EPSILON) { | ||
throw new Error('probabilities should sum to 1'); | ||
if (Math.abs(1 - cumSum[cumSum.length - 1]) > PROB_TOLERANCE) { | ||
throw new Error(`probabilities should sum to 1, but instead sums to ${cumSum[cumSum.length - 1]}`); | ||
} | ||
@@ -29,0 +30,0 @@ } |
{ | ||
"name": "ml-random", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "choose randomly from a selection of elements", | ||
"main": "lib/index.js", | ||
"module": "lib-es6/index.js", | ||
"files": ["lib", "lib-es6", "src"], | ||
"files": [ | ||
"lib", | ||
"lib-es6", | ||
"src" | ||
], | ||
"types": "lib/index.d.ts", | ||
@@ -39,3 +43,10 @@ "scripts": { | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"] | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json", | ||
"node" | ||
] | ||
}, | ||
@@ -42,0 +53,0 @@ "dependencies": { |
import { IChoiceOptions } from './Options'; | ||
import IRandomGenerator from './RandomGenerator'; | ||
const PROB_TOLERANCE = 0.00000001; | ||
function randomChoice<T>( | ||
@@ -46,4 +48,8 @@ values: T[], | ||
if (Math.abs(1 - cumSum[cumSum.length - 1]) > Number.EPSILON) { | ||
throw new Error('probabilities should sum to 1'); | ||
if (Math.abs(1 - cumSum[cumSum.length - 1]) > PROB_TOLERANCE) { | ||
throw new Error( | ||
`probabilities should sum to 1, but instead sums to ${ | ||
cumSum[cumSum.length - 1] | ||
}` | ||
); | ||
} | ||
@@ -50,0 +56,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25354
615