dstats.random

Generates random samples from a various probability distributions. These are mostly D ports of the NumPy random number generators.

auto randArray (alias randFun, Args...)(size_t N, Args args);
Convenience function to allow one-statement creation of arrays of random numbers.

Examples:
 // Create an array of 10 random numbers distributed Normal(0, 1).
 auto normals = randArray!rNorm(10, 0, 1);


R[] randArray (R, alias randFun, Args...)(size_t N, Args args);
Allows the creation of an array of random numbers with an explicitly specified type. Useful, for example, when single-precision floats are all you need.

Examples:
 // Create an array of 10 million floats distributed Normal(0, 1).
 float[] normals = randArray!(float, rNorm)(10, 0, 1);


struct RandRange (alias randFun,T...);


RandRange!(randFun,T) randRange (alias randFun, T...)(T params);
Turn a random number generator function into an infinite range. Params is a tuple of the distribution parameters. This is specified in the same order as when calling the function directly.

The sequence generated by this range is deterministic and repeatable given the state of the underlying random number generator. If the underlying random number generator is explicitly specified, as opposed to using the default thread-local global RNG, it is copied when the struct is copied. See below for an example of this behavior.

Examples:
 // Print out some summary statistics for 10,000 Poisson-distributed
 // random numbers w/ Poisson parameter 2.
 auto gen = Random(unpredictableSeed);
 auto pois1k = take(10_000, randRange!rPoisson(2, gen));
 writeln( summary(pois1k) );
 writeln( summary(pois1k) );  // Exact same results as first call.


double rNorm (RGen = Random)(double mean, double sd, ref RGen gen = rndGen);


double rCauchy (RGen = Random)(double X0, double gamma, ref RGen gen = rndGen);


double rStudentT (RGen = Random)(double df, ref RGen gen = rndGen);


double rFisher (RGen = Random)(double df1, double df2, ref RGen gen = rndGen);


double rChiSquare (RGen = Random)(double df, ref RGen gen = rndGen);


int rPoisson (RGen = Random)(double lam, ref RGen gen = rndGen);


int rBernoulli (RGen = Random)(double P = 0.5, ref RGen gen = rndGen);


int rBinomial (RGen = Random)(int n, double p, ref RGen gen = rndGen);


int rHypergeometric (RGen = Random)(int n1, int n2, int n, ref RGen gen = rndGen);


int rNegBinom (RGen = Random)(double n, double p, ref RGen gen = rndGen);


double rLaplace (RGen = Random)(double mu = 0, double b = 1, ref RGen gen = rndGen);


double rExponential (RGen = Random)(double lambda, ref RGen gen = rndGen);


double rGamma (RGen = Random)(double a, double b, ref RGen gen = rndGen);


double rBeta (RGen = Random)(double a, double b, ref RGen gen = rndGen);


double rLogistic (RGen = Random)(double loc, double scale, ref RGen gen = rndGen);


double rLogNorm (RGen = Random)(double mu, double sigma, ref RGen gen = rndGen);


double rWeibull (RGen = Random)(double shape, double scale = 1, ref RGen gen = rndGen);


double rWald (RGen = Random)(double mu, double lambda, ref RGen gen = rndGen);


double rRayleigh (RGen = Random)(double mode, ref RGen gen = rndGen);


Page was generated with on Wed May 25 22:15:55 2011