Choose randomly a value by ratio
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

choose-randomly-by-ratio

npm version Build Status

Choose randomly a value by ratio from collection

Usage

var chooseRandomlyByRatio = require('choose-randomly-by-ratio');

// This value will be 'x'(1.0/4.5) or 'y'(1.5/4.5) or 'z'(2.0/4.5)
var value = chooseRandomlyByRatio([['x', 1], ['y', 1.5], ['z', 2]]);

// It's possible to write like this
var value = chooseRandomlyByRatio({ x: 1, y: 1.5, z: 2 });

Installation

npm install choose-randomly-by-ratio

Or, you can use in browser through the browserify.