random-weighted-pick
A lightweight utility that allows you to easily choose a random item from a weighted list of items, with a probability dependent on their weight.
this module has no external dependencies and is licensed under the MIT License.
Installation & Usage
install
npm i -S random-weighted-pick
usage
// ORvar weightedPick = ;
const options = id: 0 weight: 02 console id: 1 weight: 03 item: 'Grape' 'Orange' 'Apple' id: 2 weight: 04 item: 'Mango' id: 3 weight: 01 item: 3 // Sum of 'weights' should be equal 1. const result = console // { id: 2, item: 'Mango' }
Development
install
npm install
Dependency module install
build
npm run build
Do some magic with ES6 to create ES5 code.
test
npm run test
develop
npm run dev
: Run develop server
You can see result in
-
OS X : http://0.0.0.0:8080,
-
Windows : http://localhost:8080
List of available tasks
clean
rm -f dist/*
Delete existing dist files
License
MIT License
Copyright (c) 2016 KossHackaton OneTeam