1.0.2 • Published 9 years ago

choose-randomly-by-ratio v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

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.