2.0.0 • Published 5 years ago

deep-random-pick v2.0.0

Weekly downloads
11
License
APACHE 2.0
Repository
github
Last release
5 years ago

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`);
2.0.0

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago