Random numbers from aGrUM

These functions use the pseudo-random number generator of aGrUM (mt19937). It produces 32-bit pseudo-random numbers with the Mersenne twister algorithm: mt19937 stands for Mersenne twister with a period of 219937 − 1, which means that the sequence of 32-bit integers only repeats itself after 219937 − 1 numbers have been generated.

Random functions

initRandom()

Initialize random generator seed.

randomGeneratorSeed()

Give the seed of the pseudo-random generator, to replay a sequence of draws.

randomProba()

randomNumpyGenerator()

A numpy random generator driven by the random generator of aGrUM.

randomGamma()

Draws a value of the Gamma distribution of shape shape and scale 1, with the random generator of pyAgrum.

randomShuffle()

Shuffle a sequence in place with the random generator of pyAgrum.

randomDistribution()

generateSample()

generate a CSV file of samples from a bn.

randomBN()

Creates a random BN using the (forced) keyword parameters.

Reproducible block of code

class pyagrum.RandomGeneratorGuard

Saves the state of the pseudo-random generator of pyAgrum and restores it later: a block of code can call pyagrum.initRandom and draw without changing the sequence of draws of the rest of the program.

The state (and the seed given by pyagrum.randomGeneratorSeed) is saved when the guard is created, and restored by pyagrum.RandomGeneratorGuard.restore, or at the end of a with block, even if it is left by an exception. After the restoration, the draws are the ones that would have followed the creation of the guard.

RandomGeneratorGuard() -> RandomGeneratorGuard

Notes

The generator is shared by the whole library and is not thread safe: the guard is meant for a sequential block of code.

Methods

isRestored()

restore()

Restore the seed and the state of the generator saved when the guard was created.