Weighted Random Generator
Generate random array indices weighted by given scores. Optimized for use-cases when weights are rarely or never changing.
Usage
The package exposes a factory function which takes an array of weight scores and returns the random generator function.
const wrg = random = results = 0 0 0 for let i = 0; i < 1000; i++ results ++ console
The result will be similar to the following:
[ 197, 488, 315 ]
Installation
With npm:
npm install wrg
Tests & benchmarks
Run unit tests:
npm test
Run unit tests and create coverage report:
npm run cover
Run benchmark:
npm run benchmark
License
Credits
This is an optimised version of Brandon Mills' weighted-random package.