Cyforanumera
npm

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.

NameSummary
np.standardExponentialDraw samples from the standard exponential distribution (rate=1).
np.exponentialDraw samples from an exponential distribution with given scale (inverse rate).
np.standardGammaDraw samples from a standard Gamma distribution (scale=1).
np.gammaDraw samples from a Gamma distribution.
np.betaDraw samples from a Beta distribution with shape parameters a and b.
np.chisquareDraw samples from a chi-square distribution with df degrees of freedom.
np.fDraw samples from an F distribution.
np.standardCauchyDraw samples from the standard Cauchy distribution (location=0, scale=1).
np.paretoDraw samples from a Pareto II (Lomax) distribution with shape a.
np.weibullDraw samples from a Weibull distribution with shape a.
rng.powerDraw samples from a power distribution with exponent a in (0, 1].
np.laplaceDraw samples from the Laplace (double exponential) distribution.
np.gumbelDraw samples from a Gumbel distribution.
np.logisticDraw samples from a logistic distribution.
np.lognormalDraw samples from a log-normal distribution.
np.rayleighDraw samples from a Rayleigh distribution.
np.standardTDraw samples from a standard Student's t-distribution.
np.noncentralChisquareDraw samples from a noncentral chi-square distribution.
np.noncentralFDraw samples from a noncentral F distribution.
np.waldDraw samples from a Wald (inverse Gaussian) distribution.
np.vonmisesDraw samples from a von Mises distribution.
np.triangularDraw 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

TypeScript
const rng = np.random.defaultRng(42);
rng.standardExponential(); // => 2.4042086039659947
TypeScript declaration
rng.standardExponential(size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.exponential(2); // => 4.808417207931989
TypeScript declaration
rng.exponential(scale?: number | undefined, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.standardGamma(2); // => 2.0918172704999494
TypeScript declaration
rng.standardGamma(shape: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.gamma(2, 3); // => 6.275451811499848
TypeScript declaration
rng.gamma(shape: number, scale?: number | undefined, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.beta(2, 5); // => 0.24395464376443093
TypeScript declaration
rng.beta(a: number, b: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.chisquare(2); // => 4.808417207931989
TypeScript declaration
rng.chisquare(df: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.f(2, 5); // => 6.208757071292293
TypeScript declaration
rng.f(dfnum: number, dfden: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
typeof rng.standardCauchy(); // => "number"
TypeScript declaration
rng.standardCauchy(size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.pareto(3) >= 0; // => true
TypeScript declaration
rng.pareto(a: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.weibull(1); // => 2.4042086039659947
TypeScript declaration
rng.weibull(a: number, size?: Size | null | undefined): number | NDArray

rng.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

TypeScript
const rng = np.random.defaultRng(42);
rng.power(0.5); // => 0.8274868469979773
TypeScript declaration
rng.power(a: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
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 | NDArray

np.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

TypeScript
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 | NDArray

np.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

TypeScript
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 | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.lognormal() > 0; // => true
TypeScript declaration
rng.lognormal(mean?: number | undefined, sigma?: number | undefined, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.rayleigh() > 0; // => true
TypeScript declaration
rng.rayleigh(scale?: number | undefined, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
typeof rng.standardT(2); // => "number"
TypeScript declaration
rng.standardT(df: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.noncentralChisquare(3, 1) > 0; // => true
TypeScript declaration
rng.noncentralChisquare(df: number, nonc: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.noncentralF(3, 5, 1) > 0; // => true
TypeScript declaration
rng.noncentralF(dfnum: number, dfden: number, nonc: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
rng.wald(1, 1) > 0; // => true
TypeScript declaration
rng.wald(mean: number, scale: number, size?: Size | null | undefined): number | NDArray

np.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

TypeScript
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 | NDArray

np.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

TypeScript
const rng = np.random.defaultRng(42);
const v = rng.triangular(0, 0.5, 1);
v >= 0 && v <= 1; // => true
TypeScript declaration
rng.triangular(left: number, mode: number, right: number, size?: Size | null | undefined): number | NDArray