mrg32k3a package

Submodules

mrg32k3a.matmodops module

Summary

Useful matrix/modulus operations for mrg32k3a generator.

mrg32k3a.matmodops.mat31_mod(b, m)[source]

Compute moduli of a 3 x 1 matrix.

Parameters
Returns

res – 3 x 1 matrix.

Return type

list [float]

mrg32k3a.matmodops.mat33_mat31_mult(A, b)[source]

Multiply a 3 x 3 matrix with a 3 x 1 matrix.

Parameters
Returns

res – 3 x 1 matrix.

Return type

list [float]

mrg32k3a.matmodops.mat33_mat33_mod(A, B, m)[source]

Compute moduli of a 3 x 3 matrix x 3 x 3 matrix product.

Parameters
Returns

res – 3 x 3 matrix.

Return type

list [list [float]]

mrg32k3a.matmodops.mat33_mat33_mult(A, B)[source]

Multiply a 3 x 3 matrix with a 3 x 3 matrix.

Parameters
Returns

res – 3 x 3 matrix.

Return type

list [float]

mrg32k3a.matmodops.mat33_mod(A, m)[source]

Compute moduli of a 3 x 3 matrix.

Parameters
Returns

res – 3 x 3 matrix.

Return type

list [float]

mrg32k3a.matmodops.mat33_power_mod(A, j, m)[source]

Compute moduli of a 3 x 3 matrix power. Use divide-and-conquer algorithm described in L’Ecuyer (1990).

Parameters
Returns

res – 3 x 3 matrix.

Return type

list [list [float]]

mrg32k3a.mrg32k3a module

Summary

Provide a subclass of random.Random using mrg32k3a as the generator with stream/substream/subsubstream support.

class mrg32k3a.mrg32k3a.MRG32k3a(ref_seed=(12345, 12345, 12345, 12345, 12345, 12345), s_ss_sss_index=None)[source]

Bases: Random

Implements mrg32k3a as the generator for a random.Random object.

_current_state

Current state of mrg32k3a generator.

Type

tuple [int]

ref_seed

Seed from which to start the generator. Streams/substreams/subsubstreams are referenced w.r.t. ref_seed.

Type

tuple [int]

s_ss_sss_index

Triplet of the indices of the current stream-substream-subsubstream.

Type

list [int]

stream_start

State corresponding to the start of the current stream.

Type

list [int]

substream_start

State corresponding to the start of the current substream.

Type

list [int]

subsubstream_start

State corresponding to the start of the current subsubstream.

Type

list [int]

Parameters
  • ref_seed (tuple [int], optional) – Seed from which to start the generator.

  • s_ss_sss_index (list [int], optional) – Triplet of the indices of the stream-substream-subsubstream to start at.

See also

random.Random

advance_stream()[source]

Advance the state of the generator to the start of the next stream. Streams are of length 2**141.

advance_substream()[source]

Advance the state of the generator to the start of the next substream. Substreams are of length 2**94.

advance_subsubstream()[source]

Advance the state of the generator to the start of the next subsubstream. Subsubstreams are of length 2**47.

binomialvariate(n, p)[source]

Generate a Binomial(n, p) random variate.

Parameters
  • n (int) – Number of i.i.d. Bernoulli trials; > 0.

  • p (float) – Success probability of i.i.d. Bernoulli trials; in (0, 1).

Returns

x – Binomial random variate from the specified distribution.

Return type

int

continuous_random_vector_from_simplex(n_elements, summation=1.0, exact_sum=True)[source]

Generate a random vector with a specified number of non-negative real-valued elements that sum up to (or less than or equal to) a specified number.

Parameters
  • n_elements (float) – Number of elements in the requested vector.

  • summation (float, optional) – Number to which the elements of the vector must sum.

  • exact_sum (bool, optional) – True if the sum should be equal to summation; False if the sum should be less than or equal to summation.

Returns

vec – Vector of n_elements non-negative real-valued numbers that sum up to (or less than or equal to) summation.

Return type

list [float]

get_current_state()[source]

Return the current state of the generator.

Returns

_current_state – Current state of the generator.

Return type

tuple [int]

getstate()[source]

Return the state of the generator.

Returns

  • tuple [int] – Current state of the generator, _current_state.

  • tuple [int] – Ouptput of random.Random.getstate().

See also

random.Random

gumbelvariate(mu, beta)[source]

Generate a Gumbel random variate.

Parameters
  • mu (float) – Location of the mode of the Gumbel distribution from which to generate.

  • beta (float) – Scale parameter of the Gumbel distribution from which to generate; > 0.

Returns

Gumbel random variate from the specified distribution.

Return type

float

integer_random_vector_from_simplex(n_elements, summation, with_zero=False)[source]

Generate a random vector with a specified number of non-negative integer elements that sum up to a specified number.

Parameters
  • n_elements (float) – Number of elements in the requested vector.

  • summation (int) – Number to which the integer elements of the vector must sum.

  • with_zero (bool) – True if zeros in the vector are permitted; False otherwise.

Returns

vec – A non-negative integer vector of length n_elements that sum to n_elements.

Return type

list [int]

lognormalvariate(lq, uq)[source]

Generate a Lognormal random variate using 2.5% and 97.5% quantiles

Parameters
  • lq (float) – 2.5% quantile of the lognormal distribution from which to generate.

  • uq (float) – 97.5% quantile of the lognormal distribution from which to generate.

Returns

A lognormal random variate from the specified distribution.

Return type

float

mvnormalvariate(mean_vec, cov, factorized=False)[source]

Generate a normal random vector.

Parameters
  • mean_vec (list [float]) – Location parameters of the multivariate normal distribution from which to generate.

  • cov (list [list [float]]) – Covariance matrix of the multivariate normal distribution from which to generate.

  • factorized (bool, default=False) – True if we do not need to calculate Cholesky decomposition, i.e., if Cholesky decomposition is given as cov; False otherwise.

Returns

Multivariate normal random variate from the specified distribution.

Return type

list [float]

normalvariate(mu=0, sigma=1)[source]

Generate a normal random variate.

Parameters
  • mu (float) – Expected value of the normal distribution from which to generate.

  • sigma (float) – Standard deviation of the normal distribution from which to generate.

Returns

A normal random variate from the specified distribution.

Return type

float

poissonvariate(lmbda)[source]

Generate a Poisson random variate.

Parameters

lmbda (float) – Expected value of the Poisson distribution from which to generate.

Returns

Poisson random variate from the specified distribution.

Return type

float

random()[source]

Generate a standard uniform variate and advance the generator state.

Returns

u – Pseudo uniform random variate.

Return type

float

reset_stream()[source]

Reset the state of the generator to the start of the current stream.

reset_substream()[source]

Reset the state of the generator to the start of the current substream.

reset_subsubstream()[source]

Reset the state of the generator to the start of the current subsubstream.

seed(new_state)[source]

Set the state (or seed) of the generator and update the generator state.

Parameters

new_state (tuple [int]) – New state to which to advance the generator.

setstate(state)[source]

Set the internal state of the generator.

Parameters

state (tuple) – state[0] is new state for the generator. state[1] is random.Random.getstate().

See also

random.Random

start_fixed_s_ss_sss(s_ss_sss_triplet)[source]

Set the rng to the start of a specified (stream, substream, subsubstream) triplet.

Parameters

s_ss_sss_triplet (list [int]) – Triplet of the indices of the current stream-substream-subsubstream.

mrg32k3a.mrg32k3a.bsm(u)[source]

Approximate a quantile of the standard normal distribution via the Beasley-Springer-Moro algorithm.

Parameters

u (float) – Probability value for the desired quantile (between 0 and 1).

Returns

z – Corresponding quantile of the standard normal distribution.

Return type

float

mrg32k3a.mrg32k3a.mrg32k3a(state)[source]

Generate a random number between 0 and 1 from a given state.

Parameters

state (tuple [int]) – Current state of the generator.

Returns

  • new_state (tuple [int]) – Next state of the generator.

  • u (float) – Pseudo uniform random variate.

Module contents