Random numbers.
var ns = require( '@stdlib/random' );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:
sample( x[, options] ): sample elements from an array-like object.shuffle( arr[, options] ): shuffle elements of an array-like object.
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 betaprime 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.
var logEach = require( '@stdlib/console/log-each' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var ns = require( '@stdlib/random' );
// Create a function for generating arrays originating from the same state:
var random = ns.normal.factory({
'state': ns.normal.state,
'copy': true
});
// Generate 3 one-dimensional arrays:
var x1 = random( [ 5 ], 2.0, 5.0 );
var x2 = random( [ 5 ], 2.0, 5.0 );
var x3 = random( [ 5 ], 2.0, 5.0 );
// Print the contents:
logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) );
// Create another function for generating random arrays with the original state:
random = ns.normal.factory({
'state': ns.normal.state,
'copy': true
});
// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence:
var x4 = random( [ 3, 5 ], 2.0, 5.0 );
// Convert to a list of nested arrays:
var arr = ndarray2array( x4 );
// Print the contents:
console.log( '' );
logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] );