weighted-randomness
TypeScript icon, indicating that this package has built-in type declarations

0.0.4-alpha.0 • Public • Published

weighted-randomness

Generate a weighted random function from a frequency map. Every time the returned function is called, it'll return one of the words inside freqMap.

Install

  • npm i weighted-randomness

Usage

import weightedRandomness from 'weighted-randomness';

const freqMap = {
  1: ['qux'],
  2: ['bar', 'baz'],
  4: ['foo'],
};

const randomFn = weightedRandomness(freqMap);

for (let i = 0; i < 10; i++) console.log(randomFn());

Package Sidebar

Install

npm i weighted-randomness

Weekly Downloads

0

Version

0.0.4-alpha.0

License

MIT

Unpacked Size

9.35 kB

Total Files

10

Last publish

Collaborators

  • gusalbukrk