About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Random
Random numbers.
Installation
npm install @stdlib/random
Alternatively,
- To load the package in a website via a
script tag without installation and bundlers, use the ES Module available on the esm branch (see README).
- If you are using Deno, visit the
deno branch (see README for usage intructions).
- For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umd branch (see README).
The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
Usage
var ns = require( '@stdlib/random' );
ns
Namespace containing random number functionality.
var arr = ns.normal( [ 3, 3 ], 2.0, 5.0 );
// returns <ndarray>
The namespace exports the following functions to sample and shuffle elements from an array:
The namespace contains the following functions for generating pseudorandom values drawn from probability distributions:
arcsine( shape, a, b[, options] ): generate pseudorandom numbers drawn from an arcsine distribution.
bernoulli( shape, p[, options] ): generate pseudorandom numbers drawn from a Bernoulli distribution.
beta( shape, a, b[, options] ): generate pseudorandom numbers drawn from a beta distribution.
betaprime( shape, alpha, beta[, options] ): generate pseudorandom numbers drawn from a beta prime distribution.
binomial( shape, n, p[, options] ): generate pseudorandom numbers drawn from a binomial distribution.
cauchy( shape, x0, gamma[, options] ): generate pseudorandom numbers drawn from a Cauchy distribution.
chi( shape, k[, options] ): generate pseudorandom numbers drawn from a chi distribution.
chisquare( shape, k[, options] ): generate pseudorandom numbers drawn from a chi-square distribution.
cosine( shape, mu, s[, options] ): generate pseudorandom numbers drawn from a raised cosine distribution.
discreteUniform( shape, a, b[, options] ): generate pseudorandom numbers drawn from a discrete uniform distribution.
erlang( shape, k, lambda[, options] ): generate pseudorandom numbers drawn from an Erlang distribution.
exponential( shape, lambda[, options] ): generate pseudorandom numbers drawn from an exponential distribution.
f( shape, d1, d2[, options] ): generate pseudorandom numbers drawn from an F distribution.
frechet( shape, alpha, s, m[, options] ): generate pseudorandom numbers drawn from a Fréchet distribution.
gamma( shape, alpha, beta[, options] ): generate pseudorandom numbers drawn from a gamma distribution.
geometric( shape, p[, options] ): generate pseudorandom numbers drawn from a geometric distribution.
gumbel( shape, mu, beta[, options] ): generate pseudorandom numbers drawn from a Gumbel distribution.
hypergeometric( shape, N, K, n[, options] ): generate pseudorandom numbers drawn from a hypergeometric distribution.
invgamma( shape, alpha, beta[, options] ): generate pseudorandom numbers drawn from an inverse gamma distribution.
kumaraswamy( shape, a, b[, options] ): generate pseudorandom numbers drawn from a Kumaraswamy distribution.
laplace( shape, mu, b[, options] ): generate pseudorandom numbers drawn from a Laplace (double exponential) distribution.
levy( shape, mu, c[, options] ): generate pseudorandom numbers drawn from a Lévy distribution.
logistic( shape, mu, s[, options] ): generate pseudorandom numbers drawn from a logistic distribution.
lognormal( shape, mu, sigma[, options] ): generate pseudorandom numbers drawn from a lognormal distribution.
negativeBinomial( shape, r, p[, options] ): generate pseudorandom numbers drawn from a negative binomial distribution.
normal( shape, mu, sigma[, options] ): generate pseudorandom numbers drawn from a normal distribution.
pareto1( shape, alpha, beta[, options] ): generate pseudorandom numbers drawn from a Pareto (Type I) distribution.
poisson( shape, lambda[, options] ): generate pseudorandom numbers drawn from a Poisson distribution.
rayleigh( shape, sigma[, options] ): generate pseudorandom numbers drawn from a Rayleigh distribution.
t( shape, v[, options] ): generate pseudorandom numbers drawn from a Student's t-distribution.
triangular( shape, a, b, c[, options] ): generate pseudorandom numbers drawn from a triangular distribution.
uniform( shape, a, b[, options] ): generate pseudorandom numbers drawn from a continuous uniform distribution.
weibull( shape, k, lambda[, options] ): generate pseudorandom numbers drawn from a Weibull distribution.
The namespace contains the following sub-namespaces:
array: pseudorandom number generator (PRNG) array creation functions.
base: base (i.e., lower-level) pseudorandom number generators (PRNGs).
iterators: pseudorandom number generator (PRNG) iterators.
streams: pseudorandom number generator (PRNG) streams.
strided: pseudorandom number generator (PRNG) strided array functions.
Examples