npm.io
1.0.3 • Published 7 years ago

wariai

Licence
MIT
Version
1.0.3
Deps
0
Size
20 kB
Vulns
0
Weekly
0

Wariai

Shuffles randomly a list or pick an option among several weighted ones

Install

With npm : npm install wariai

First, create a JSON string containing your options & weights following this pattern :

let obj = '[{ "option": "test1", "weight": 1},{ "option": "test2", "weight": 2},{ "option": "test3", "weight": 3},{ "option": "test4", "weight": 4}]';

Then, create the picker object :

let picker = new Picker(obj);

You can now pick an element or shuffle the list with the following code :

picker.pickOneWithWeight(); // Returns a random object from the list, taking weights into account
picker.getRandomizedList(); // Returns a randomly shuffled list of elements

Keywords