wror
v1.0.0
Published
Generate array indices with round-robin distribution, weighted by given scores.
Downloads
17
Maintainers
Readme
Weighted Round-Robin Arbiter
Generate array indices with round-robin distribution, weighted by given scores.
Usage
The package exposes a factory function which takes an array of weight scores and returns the arbiter function.
const wror = require('./'),
next = wror([ 2, 5, 3 ]),
counts = [ 0, 0, 0 ],
order = []
for (let i = 0; i < 10; i++) {
let n = next()
counts[ n ]++
order.push(n)
}
console.log(counts)
console.log(order.join(''))
The result will be the following:
[ 2, 5, 3 ]
1112120120
Installation
With npm:
npm install wror
Tests & benchmarks
Run unit tests:
npm test
Run unit tests and create coverage report:
npm run cover