0.0.4-alpha.0 • Published 12 months ago

weighted-randomness v0.0.4-alpha.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

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());