Skip to content

mafintosh/random-weighted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Produce a random integer based on weights

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages