Usage:
import betterr.random;
This module exposes all of the random number generation function in base R to a D program.
struct Sample {
Vector x;
long size;
bool replace = false;
Vector prob;
}
x: Vector holding the data to be sampled.size: Number of elements to sample from x.replace: True if sampling from x is done with replacement.prob: A vector specifying the probabilities of drawing each of the elements of x.draw(): Return a vector holding the sample drawn based on the configuration you have specified.See also: R documentation
Vector rnorm(long n, double mean=0, double sd=1)
n: Number of drawsmeansd: Standard deviationSee also: rnorm
Vector runif(long n, double min=0, double max=1)
n: Number of drawsminmaxSee also: runif
Vector rgamma(long n, double shape, double rate=double.nan, double scale=1.0)
R has named optional parameters. D does not. Set rate to double.nan to leave it unspecified.
n: Number of drawsshaperatescaleSee also: rgamma
Vector rbeta(long n, double shape1, double shape2, double ncp=0.0)
n: Number of drawsshape1shape2ncp: Non-centrality parameterSee also: rbeta
Vector rbinom(long n, long size, double prob)
n: Number of drawssize: Number of trialsprob: Probability of success on each trialSee also: rbinom
Vector rcauchy(long n, double location=0, double scale=1)
n: Number of drawslocationscaleSee also: rcauchy
Vector rchisq(long n, double df, double ncp)
n: Number of drawsdf: Degrees of freedom (>= 0)ncp: Non-centrality parameter (>= 0)See also: rchisq
Vector rexp(long n, double rate=1.0)
n: Number of drawsrate: Mean is 1/rateSee also: rexp
Vector rf(long n, long df1, long df2, double ncp)
Vector rf(long n, long df1, long df2)
n: Number of drawsdf1: First degrees of freedom parameterdf2: Second degrees of freedom parameterncp: Non-centrality parameterSee also: rf
Vector rgeom(T)(long n, T prob)
n: Number of drawsprob: A Vector of probabilities or anything that converts to a Vector, including a double[].See also: rgeom
Vector rhyper(long nn, long m, long n, long k)
Vector rhyper(Vector nn, long m, long n, long k)
Vector rhyper(long[] nn, long m, long n, long k)
nn: Number of draws (observations). If it is Vector or long[], then the number of draws is the number of elements of nn. This is consistent with the behavior of the underlying R function.m: Number of white ballsn: Number of black ballsk: Number of balls that are drawn from the urn to generate each observationSee also: rhyper
Vector rlnorm(long n, double meanlog=0, double sdlog=1)
n: Number of drawsmeanlog: Mean of the distribution on the logscalesdlog: Standard deviation of the distribution on the logscaleSee also: rlnorm
Matrix rmultinom(T)(long n, long size, T prob)
n: Number of random vectors to drawsize: Total number of elements drawnprob: Vector of probabilities of each of the elements that are drawn. The number of elements in each of the n vectors is size/prob.rows. prob can be a Vector, or anything that converts to a Vector.See also: rmultinom
Vector rnbinom(long n, double size, double prob, double mu)
Vector rnbinom(Vector n, double size, double prob, double mu)
Vector rnbinom(T)(T[] n, double size, double prob, double mu)
Vector rnbinom(long n, double size, double prob)
Vector rnbinom(Vector n, double size, double prob)
Vector rnbinom(T)(T[] n, double size, double prob)
n: Number of drawssize: Target for number of successful trialsprob: Probability of success in each trialmu: Alternative to specifying probIf you want to specify mu rather than prob, set prob to double.nan. If n is a Vector or converts to a Vector, then the number of draws is n.rows.
See also: rnbinom
Vector rpois(double n, double lambda)
n: Number of drawslambda: MeanSee also: rpois
Vector rt(long n, double df, double ncp)
Vector rt(long n, double df)
Vector rt(Vector n, double df, double ncp)
Vector rt(Vector n, double df)
Vector rt(T)(T[] n, double df, double ncp)
Vector rt(T)(T[] n, double df)
n: Number of draws. If n is a Vector or converts to a Vector, the number of draws is n.rows.df: Degrees of freedomncp: Non-centrality parameterSee also: rt
Vector rweibull(long n, double shape, double scale=1.0)
n: Number of drawsshapescaleSee also: rweibull