API reference
Random — continuous distributions (Generator)
Continuous distribution samplers on np.random.Generator. Obtain a generator with np.random.defaultRng(seed). All methods return a JS number when size is omitted and a float64 NDArray otherwise.
| Name | Summary |
|---|---|
np.standardExponential | Draw samples from the standard exponential distribution (rate=1). |
np.exponential | Draw samples from an exponential distribution with given scale (inverse rate). |
np.standardGamma | Draw samples from a standard Gamma distribution (scale=1). |
np.gamma | Draw samples from a Gamma distribution. |
np.beta | Draw samples from a Beta distribution with shape parameters a and b. |
np.chisquare | Draw samples from a chi-square distribution with df degrees of freedom. |
np.f | Draw samples from an F distribution. |
np.standardCauchy | Draw samples from the standard Cauchy distribution (location=0, scale=1). |
np.pareto | Draw samples from a Pareto II (Lomax) distribution with shape a. |
np.weibull | Draw samples from a Weibull distribution with shape a. |
rng.power | Draw samples from a power distribution with exponent a in (0, 1]. |
np.laplace | Draw samples from the Laplace (double exponential) distribution. |
np.gumbel | Draw samples from a Gumbel distribution. |
np.logistic | Draw samples from a logistic distribution. |
np.lognormal | Draw samples from a log-normal distribution. |
np.rayleigh | Draw samples from a Rayleigh distribution. |
np.standardT | Draw samples from a standard Student's t-distribution. |
np.noncentralChisquare | Draw samples from a noncentral chi-square distribution. |
np.noncentralF | Draw samples from a noncentral F distribution. |
np.wald | Draw samples from a Wald (inverse Gaussian) distribution. |
np.vonmises | Draw samples from a von Mises distribution. |
np.triangular | Draw samples from a triangular distribution over [left, right] with peak at mode. |
np.standardExponential
#rng.standardExponential(size?)
Draw samples from the standard exponential distribution (rate=1). Equivalent to numpy.random.Generator.standard_exponential.
Parameters
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.standardExponential(); // => 2.4042086039659947TypeScript declaration
rng.standardExponential(size?: Size | null | undefined): number | NDArraynp.exponential
#rng.exponential(scale?, size?)
Draw samples from an exponential distribution with given scale (inverse rate). Equivalent to numpy.random.Generator.exponential.
Parameters
[scale]number- Scale (1/rate). Default 1.0.
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.exponential(2); // => 4.808417207931989TypeScript declaration
rng.exponential(scale?: number | undefined, size?: Size | null | undefined): number | NDArraynp.standardGamma
#rng.standardGamma(shape, size?)
Draw samples from a standard Gamma distribution (scale=1). Equivalent to numpy.random.Generator.standard_gamma.
Parameters
shapenumber- Shape parameter (> 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.standardGamma(2); // => 2.0918172704999494TypeScript declaration
rng.standardGamma(shape: number, size?: Size | null | undefined): number | NDArraynp.gamma
#rng.gamma(shape, scale?, size?)
Draw samples from a Gamma distribution. Equivalent to numpy.random.Generator.gamma.
Parameters
shapenumber- Shape parameter (> 0).
[scale]number- Scale parameter (> 0). Default 1.0.
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.gamma(2, 3); // => 6.275451811499848TypeScript declaration
rng.gamma(shape: number, scale?: number | undefined, size?: Size | null | undefined): number | NDArraynp.beta
#rng.beta(a, b, size?)
Draw samples from a Beta distribution with shape parameters a and b. Equivalent to numpy.random.Generator.beta.
Parameters
anumber- Alpha shape parameter (> 0).
bnumber- Beta shape parameter (> 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.beta(2, 5); // => 0.24395464376443093TypeScript declaration
rng.beta(a: number, b: number, size?: Size | null | undefined): number | NDArraynp.chisquare
#rng.chisquare(df, size?)
Draw samples from a chi-square distribution with df degrees of freedom. Equivalent to numpy.random.Generator.chisquare.
Parameters
dfnumber- Degrees of freedom (> 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.chisquare(2); // => 4.808417207931989TypeScript declaration
rng.chisquare(df: number, size?: Size | null | undefined): number | NDArraynp.f
#rng.f(dfnum, dfden, size?)
Draw samples from an F distribution. Equivalent to numpy.random.Generator.f.
Parameters
dfnumnumber- Numerator degrees of freedom (> 0).
dfdennumber- Denominator degrees of freedom (> 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.f(2, 5); // => 6.208757071292293TypeScript declaration
rng.f(dfnum: number, dfden: number, size?: Size | null | undefined): number | NDArraynp.standardCauchy
#rng.standardCauchy(size?)
Draw samples from the standard Cauchy distribution (location=0, scale=1). Equivalent to numpy.random.Generator.standard_cauchy.
Parameters
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
typeof rng.standardCauchy(); // => "number"TypeScript declaration
rng.standardCauchy(size?: Size | null | undefined): number | NDArraynp.pareto
#rng.pareto(a, size?)
Draw samples from a Pareto II (Lomax) distribution with shape a. Equivalent to numpy.random.Generator.pareto.
Parameters
anumber- Shape parameter (> 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.pareto(3) >= 0; // => trueTypeScript declaration
rng.pareto(a: number, size?: Size | null | undefined): number | NDArraynp.weibull
#rng.weibull(a, size?)
Draw samples from a Weibull distribution with shape a. Equivalent to numpy.random.Generator.weibull.
Parameters
anumber- Shape parameter (>= 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.weibull(1); // => 2.4042086039659947TypeScript declaration
rng.weibull(a: number, size?: Size | null | undefined): number | NDArrayrng.power
#rng.power(a, size?)
Draw samples from a power distribution with exponent a in (0, 1]. Equivalent to numpy.random.Generator.power.
Parameters
anumber- Exponent in (0, 1].
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.power(0.5); // => 0.8274868469979773TypeScript declaration
rng.power(a: number, size?: Size | null | undefined): number | NDArraynp.laplace
#rng.laplace(loc?, scale?, size?)
Draw samples from the Laplace (double exponential) distribution. Equivalent to numpy.random.Generator.laplace.
Parameters
[loc]number- Location (mean). Default 0.0.
[scale]number- Scale (>= 0). Default 1.0.
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
typeof rng.laplace(); // => "number"TypeScript declaration
rng.laplace(loc?: number | undefined, scale?: number | undefined, size?: Size | null | undefined): number | NDArraynp.gumbel
#rng.gumbel(loc?, scale?, size?)
Draw samples from a Gumbel distribution. Equivalent to numpy.random.Generator.gumbel.
Parameters
[loc]number- Location. Default 0.0.
[scale]number- Scale (>= 0). Default 1.0.
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
typeof rng.gumbel(); // => "number"TypeScript declaration
rng.gumbel(loc?: number | undefined, scale?: number | undefined, size?: Size | null | undefined): number | NDArraynp.logistic
#rng.logistic(loc?, scale?, size?)
Draw samples from a logistic distribution. Equivalent to numpy.random.Generator.logistic.
Parameters
[loc]number- Location. Default 0.0.
[scale]number- Scale (>= 0). Default 1.0.
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
typeof rng.logistic(); // => "number"TypeScript declaration
rng.logistic(loc?: number | undefined, scale?: number | undefined, size?: Size | null | undefined): number | NDArraynp.lognormal
#rng.lognormal(mean?, sigma?, size?)
Draw samples from a log-normal distribution. Equivalent to numpy.random.Generator.lognormal.
Parameters
[mean]number- Mean of the underlying normal. Default 0.0.
[sigma]number- Std dev of underlying normal (>= 0). Default 1.0.
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.lognormal() > 0; // => trueTypeScript declaration
rng.lognormal(mean?: number | undefined, sigma?: number | undefined, size?: Size | null | undefined): number | NDArraynp.rayleigh
#rng.rayleigh(scale?, size?)
Draw samples from a Rayleigh distribution. Equivalent to numpy.random.Generator.rayleigh.
Parameters
[scale]number- Scale parameter (>= 0). Default 1.0.
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.rayleigh() > 0; // => trueTypeScript declaration
rng.rayleigh(scale?: number | undefined, size?: Size | null | undefined): number | NDArraynp.standardT
#rng.standardT(df, size?)
Draw samples from a standard Student's t-distribution. Equivalent to numpy.random.Generator.standard_t.
Parameters
dfnumber- Degrees of freedom (> 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
typeof rng.standardT(2); // => "number"TypeScript declaration
rng.standardT(df: number, size?: Size | null | undefined): number | NDArraynp.noncentralChisquare
#rng.noncentralChisquare(df, nonc, size?)
Draw samples from a noncentral chi-square distribution. Equivalent to numpy.random.Generator.noncentral_chisquare.
Parameters
dfnumber- Degrees of freedom (> 0).
noncnumber- Noncentrality parameter (>= 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.noncentralChisquare(3, 1) > 0; // => trueTypeScript declaration
rng.noncentralChisquare(df: number, nonc: number, size?: Size | null | undefined): number | NDArraynp.noncentralF
#rng.noncentralF(dfnum, dfden, nonc, size?)
Draw samples from a noncentral F distribution. Equivalent to numpy.random.Generator.noncentral_f.
Parameters
dfnumnumber- Numerator degrees of freedom (> 0).
dfdennumber- Denominator degrees of freedom (> 0).
noncnumber- Noncentrality parameter (>= 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.noncentralF(3, 5, 1) > 0; // => trueTypeScript declaration
rng.noncentralF(dfnum: number, dfden: number, nonc: number, size?: Size | null | undefined): number | NDArraynp.wald
#rng.wald(mean, scale, size?)
Draw samples from a Wald (inverse Gaussian) distribution. Equivalent to numpy.random.Generator.wald.
Parameters
meannumber- Distribution mean (> 0).
scalenumber- Scale parameter (> 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
rng.wald(1, 1) > 0; // => trueTypeScript declaration
rng.wald(mean: number, scale: number, size?: Size | null | undefined): number | NDArraynp.vonmises
#rng.vonmises(mu, kappa, size?)
Draw samples from a von Mises distribution. Equivalent to numpy.random.Generator.vonmises.
Parameters
munumber- Mode angle in radians.
kappanumber- Concentration parameter (>= 0).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
typeof rng.vonmises(0, 1); // => "number"TypeScript declaration
rng.vonmises(mu: number, kappa: number, size?: Size | null | undefined): number | NDArraynp.triangular
#rng.triangular(left, mode, right, size?)
Draw samples from a triangular distribution over [left, right] with peak at mode. Equivalent to numpy.random.Generator.triangular.
Parameters
leftnumber- Lower bound.
modenumber- Peak value in [left, right].
rightnumber- Upper bound (> left).
[size]number | number[]- Output shape; omit for a scalar.
Returns
number | NDArray<float64>
Example
const rng = np.random.defaultRng(42);
const v = rng.triangular(0, 0.5, 1);
v >= 0 && v <= 1; // => trueTypeScript declaration
rng.triangular(left: number, mode: number, right: number, size?: Size | null | undefined): number | NDArray