sampling
JavaScript for sampling from a handful of discrete probability distributions
Setup
This is now a node module on npm. To install, go to your project's directory in
a terminal and enter
npm install discrete-sampling
To load the library in your own node module, use
var SJS = Sampling = ;
To load the module in the browser, you can load the script with
and then the library will be accessible through the global variables SJS
and
Sampling
.
Currently Supported
- Bernoulli
- Binomial
- Discrete
- Multinomial
- Poisson
- Negative Binomial
Examples
var bern = Sampling;bern; // One random drawbern; // Get an array of 10 samples.
var binom = SJS; // alternate syntax (Sampling === SJS)binom;binom;
var probabilities = 1 2 3 05 15;var disc = SJS;disc; disc;
// The probabilities will be normalized for you. var probs = 11111111111111var mult = SJS;mult;mult;
var myArray = 012345// sample five elements with replacement// sample five elements without replacement