Have ideas to improve npm?Join in the discussion! »

    random-weighted-item

    1.1.3 • Public • Published

    random-weighted-item

    MIT License Build Status

    NPM status

    JavaScript library to get random item from an array by probability function. The probability function takes the current value and the current index respectively as arguments. The real probability to obtain a particular item is Math.exp(probabilityFunctionReturnedValue).

    install

    npm install --save random-weighted-item

    usage

    const getRandomItem = require('random-weighted-item').default;
    
    const array = [3, 7, 1, 4, 2];
    const getWeight = value => value;
    getRandomItem(array, getWeight);

    for other examples see https://github.com/oprogramador/random-weighted-item/blob/master/src/tests/getRandomItem.js

    Install

    npm i random-weighted-item

    DownloadsWeekly Downloads

    9

    Version

    1.1.3

    License

    MIT

    Unpacked Size

    3.66 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar