ivoire-weighted-choice
Weighted choices for the Ivoire random number generator framework.
Last updated 5 years ago by eykd .
BSD · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ivoire-weighted-choice 
SYNC missed versions from official npm registry.

ivoire-weighted-choice

Weighted choices for the Ivoire random number generator framework.

Installing

To install, use npm:

npm install ivoire-weighted-choice

Alternately, you can find the source on Github.

Getting Started

ivoire-weighted-choice extends the ivoire package. You can require it directly:

var Ivoire = require('ivoire-weighted-choice');

Or you can require it alongside ivoire:

var Ivoire = require('ivoire');
require('ivoire-weighted-choice');

Either way, instantiate and start making weighted choices!

var i = new Ivoire();
i.weighted_choice(['foo', 'bar'], [10, 1]);

Reference

ivoire-weighted-choice adds some methods to the Ivoire prototype object, making them available on all Ivoire instances.

#weighted_choice(options, weights)

Randomly choose an option, choosing more heavily-weighted options more often than lightly-weighted options.

var i = new require('ivoire-weighted-choice');

// 'foo' will come up 10 times for every 1 time that 'bar' comes up
i.weighted_choice(['foo', 'bar'], [10, 1]);

Acknowledgements

Weighted choice algorithm based on the implementation in Darmok.

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

1 Versions

  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (3)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |