deep-random-pick

2.0.0 • Public • Published

Deep-Random Pick - recursive random picker

A simple Javascript library made to pick random items from a pool through multiple (optional) layers.

Features

Deep-Random-Pick allows for numerous ways to pick from a pool, with control over probability.

Deep Random Pick

Deep-Random-Pick's name comes from the deepRandomPick function (or just randomPick for brevity). This function picks from its arguments recursively, offering much more control over probability than shallowPick. However, the only time when randomPick can return an array is when the last item picked is an empty array.

import * as randomPick from 'deep-random-pick';
 
let foo = ['bar', ['sploop']];

randomPick(foo);
// Will output either 'bar' or 'sploop', but not ['sploop']
 
randomPick(foo, [69, 420], []);
// Can output 'bar','sploop', 69, 420, or [] 

To better exemplify how the deep random pick works, here's a rather ugly function that will output the likelihood of its output.

console.log(`${randomPick(.5,[.25,[.125,[.0625, .0625]]]) * 100}% chance`);

/deep-random-pick/

    Package Sidebar

    Install

    npm i deep-random-pick

    Weekly Downloads

    1

    Version

    2.0.0

    License

    APACHE 2.0

    Unpacked Size

    16.9 kB

    Total Files

    12

    Last publish

    Collaborators

    • davi_danger