wror

1.0.0 • Public • Published

view on npm downloads per month node version build status test coverage license

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

License

MIT

Package Sidebar

Install

npm i wror

Weekly Downloads

7

Version

1.0.0

License

MIT

Last publish

Collaborators

  • schwarzkopfb