Skip to content

carewdavid/random-choice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

random-choice

Get a random item from an array with a weighted probability

Install

$ npm install random-choice

Usage

const randomChoice = require('random-choice');

//Give relative weights 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published