1.0.0 • Published 7 years ago

random-weighted v1.0.0

Weekly downloads
7,478
License
MIT
Repository
github
Last release
7 years ago

random-weighted

Produce a random integer based on weights.

npm install random-weighted

build status

Usage

var random = require('random-weighted')
var weights = [0.2, 0.5, 0.3] // should add up to 1
console.log(random(weights)) // random number between 0-2 (there are 3 weights)

API

var num = random(weights)

Produce a random number between 0 and weights.length - 1.

The random number will be picked at the probability of defined be the weights array. All probabilities in the weights array should add up to 1.

License

MIT