Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ml-random

Package Overview
Dependencies
Maintainers
5
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-random - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

10

History.md

@@ -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)

5

lib-es6/choice.js

@@ -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 @@ }

17

package.json
{
"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 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc