Skip to content

Generate array indices with round-robin distribution, weighted by given scores.

License

Notifications You must be signed in to change notification settings

schwarzkopfb/wror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Generate array indices with round-robin distribution, weighted by given scores.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published