Socket
Socket
Sign inDemoInstall

chance.js

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chance.js

Simplest & smallest random weighted function execution library, so that you can execute weighted functions with ease.


Version published
Weekly downloads
33
decreased by-2.94%
Maintainers
1
Install size
4.55 kB
Created
Weekly downloads
 

Readme

Source

chance.js

Simplest & smallest random weighted function execution library, so that you can execute weighted functions with ease.

Installation

$ npm install chance.js

Example

var Chance = require('chance.js');

var result = {
    05: 0,
    15: 0,
    20: 0,
    60: 0
};

var chance = new Chance([{
    w: 60, // weight: 60%
    f: function (v) { // functions can accept arguments
        result[60]++;
    }
}, {
    w: 15, // weight: 15%
    f: function (v) {
        result[15]++;
    }
}, {
    w: 20, // weight: 20%
    f: function (v) {
        result[20]++;
    }
}, {
    w: 5, // weight: 05%
    f: function (v) {
        result[05]++;
    }
}]);


for (var i = 0; i < 100; i++) {
    chance.next('some arg'); // you can pass arguments
};

console.log(result);

Keywords

FAQs

Last updated on 16 Feb 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc