random-choice

1.0.0 • Public • Published

random-choice

Get a random item from an array with a weighted probablility

Install

$ npm install random-choice

Usage

const randomChoice = require('random-choice');
 
//Give relative wqeights for the items in your array
randomChoice(['apple', 'orange', 'banana'], [.50, .25, .25]);
//=> 'apple'
 
//Integer ratios work too
randomChoice(['apple', 'orange', 'banana'], [2, 1, 1]);
//=> 'apple'

License

MIT

Package Sidebar

Install

npm i random-choice

Weekly Downloads

30

Version

1.0.0

License

MIT

Unpacked Size

3.15 kB

Total Files

4

Last publish

Collaborators

  • carewdavid