mtalg.random.MultithreadedRNG

class MultithreadedRNG(seed: int | None = None, num_threads: int | None = None, bit_generator: ~numpy.random.bit_generator.BitGenerator = <class 'numpy.random._pcg64.PCG64'>)[source]

Multithreaded random number generator.

Parameters:
  • seed (int) – Random seed.

  • num_threads (int) – Number of threads to be used, overrides threads as set by set_num_threads().

  • bit_generator (np.random.BitGenerator) – Bit generator, defaults to PCG64.

Examples

Instantiate a multithreaded random number generator which uses 4 threads, setting a seed to derive the initial BitGenerator state.

>>> from mtalg.random import MultithreadedRNG
>>> mrng = MultithreadedRNG(seed=1, num_threads=4)

Create a 10000 x 5000 matrix with numbers, drawing from the standard normal distribution.

>>> a = mrng.standard_normal(size=(10_000, 5_000))

Create a 10000 x 5000 matrix with numbers, drawing from the uniform distribution.

>>> b = mrng.uniform(size=(10_000, 5_000), low=0, high=10)

Note

For more information on distributions, see Random generator distributions.

Methods

beta(a, b[, size])

Draw from a beta distribution.

binomial(n, p[, size])

Draw from a binomial distribution.

chisquare(df[, size])

Draw from a chisquare distribution.

exponential([scale, size])

Draw from an exponential distribution.

f(dfnum, dfden[, size])

Draw from an F distribution.

gamma(shape[, scale, size])

Draw from a gamma distribution.

geometric(p[, size])

Draw from a geometric distribution.

gumbel([loc, scale, size])

Draw from a Gumbel distribution.

hypergeometric(ngood, nbad, nsample[, size])

Draw from a hypergeometric distribution.

integers(low[, high, size, dtype, endpoint])

Draw random integers from low (inclusive) to high (exclusive), or if endpoint=True, low (inclusive) to high (inclusive).

laplace([loc, scale, size])

Draw from a Laplace distribution.

logistic([loc, scale, size])

Draw from a logistic distribution.

lognormal([mean, sigma, size])

Draw from a lognormal distribution.

logseries(p[, size])

Draw from a logarithmic series distribution.

negative_binomial(n, p[, size])

Draw from a negative binomial distribution.

noncentral_chisquare(df, nonc[, size])

Draw from a noncentral chisquare distribution.

noncentral_f(dfnum, dfden, nonc[, size])

Draw from a noncentral F distribution.

normal([loc, scale, size])

Draw from the normal distribution.

pareto(a[, size])

Draw from a Pareto II or Lomax distribution.

poisson([lam, size])

Draw from a poisson distribution.

power(a[, size])

Draw from a power distribution.

random([size, dtype])

Return random floats in the half-open interval [0.0, 1.0).

rayleigh([scale, size])

Draw from a Rayleigh distribution.

standard_cauchy([size])

Draw from a standard Cauchy distribution.

standard_exponential([size, dtype, method])

Draw from a standard exponential distribution.

standard_gamma(shape[, size, dtype])

Draw from a standard gamma distribution.

standard_normal([size, dtype])

Draw from a standard normal distribution.

standard_t(df[, size])

Draw from a standard Student’s t distribution.

triangular(left, mode, right[, size])

Draw from a triangular distribution.

uniform([low, high, size])

Draw from a uniform distribution.

vonmises(mu, kappa[, size])

Draw from a von Mises distribution.

wald(mean, scale[, size])

Draw from a Wald distribution.

weibull(a[, size])

Draw from a Weibull distribution.

zipf(a[, size])

Draw from a Zipf distribution.