pylag.random module

This Cython module has the purpose of providing clients with rapid access to pseudo random numbers generated the Mersenne Twister pseudo random number generator.

Note

random is implemented in Cython. Only a small portion of the API is exposed in Python with accompanying documentation.

class pylag.random.Pymt19937

Bases: object

Cython wrapper class for mt19937

Parameters

seed (float) – Seed for the PRNG.

pylag.random.gauss(DTYPE_FLOAT_t mean=0.0, DTYPE_FLOAT_t std=1.0) DTYPE_FLOAT_t

Generate a random Gaussian variate. The Gaussian distribution has a standard deviation of std, and a mean of 0.0.

Parameters

std (float, optional) – Standard deviation of the Gaussian distribution.

Returns

variate – Random Gaussian variate

Return type

float

pylag.random.get_seed()

Return the value of the seed used with the PRNG.

Returns

_seed – The seed.

Return type

float

pylag.random.seed(seed=None)

Seed the random number generator If seed is None, use a combination of the system time and processor ID to set the random seed. The approach ensures each worker uses a unique seed during parallel simulations. Algorithm adapted from http://goo.gl/BVxgFl.

Parameters

seed (long, optional) – The seed to be used.

pylag.random.uniform(DTYPE_FLOAT_t a=-1.0, DTYPE_FLOAT_t b=1.0) DTYPE_FLOAT_t

Generate a random variate within the range [a, b].

Parameters
  • a (float, optional) – Lower limit

  • b (float, optional) – Upper limit

Returns

variate – Random variate

Return type

float