mrpt.random

mrpt.random — Random number generation utilities.

Provides:
  • CRandomGenerator : Mersenne Twister PRNG with Gaussian/uniform sampling

  • getRandomGenerator() : Global singleton accessor

  • Randomize(seed) : Seed the global generator

Example:

import mrpt.random as rng
g = rng.CRandomGenerator(42)
x = g.drawGaussian1D(mean=0.0, std=1.0)
arr = g.drawGaussianArray(1000, mean=0.0, std=1.0)  # numpy array
xy = g.drawGaussianMultivariateMany(100, [[1.0, 0.5], [0.5, 2.0]])  # (100, 2)

Package Contents

class mrpt.random.CRandomGenerator

C++ API: class mrpt::random::CRandomGenerator

CRandomGenerator(seed: int)

drawGaussian1D(mean: float, std: float) → float

Draw a sample from N(mean, std)

drawGaussian1D_normalized() → float

Draw a sample from N(0,1)

drawGaussianArray(n: int, mean: float = 0.0, std: float = 1.0) → numpy.ndarray

Draw n Gaussian samples as a 1D float64 numpy array

drawGaussianMultivariate(cov, mean=None)

Draw one sample from N(mean, cov) as a 1D numpy array (zero mean if None).

drawGaussianMultivariateMany(n, cov, mean=None)

Draw n samples from N(mean, cov) as the rows of an (n, dim) numpy array.

Zero mean if mean is None. cov must be symmetric and positive semi-definite; an eigen-decomposition (not Cholesky) is used, so singular covariances are accepted, like the C++ CRandomGenerator::drawGaussianMultivariate().

drawUniform(min: float, max: float) → float

Draw a uniform double from [min, max)

drawUniform32bit() → int
drawUniform64bit() → int
drawUniformArray(n: int, min: float = 0.0, max: float = 1.0) → numpy.ndarray

Draw n uniform samples as a 1D float64 numpy array

randomize(seed: int) → None
randomize() → None

Initialize the PRNG from the current time (non-deterministic)

mrpt.random.Randomize(seed: int) → None
mrpt.random.Randomize() → None

Seed the global random generator from the current time

mrpt.random.getRandomGenerator() → CRandomGenerator

Returns the global MRPT random generator singleton