randomNumpyGenerator

pyagrum.randomNumpyGenerator()

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

The seed of the returned generator is drawn from the random generator of aGrUM: pyagrum.initRandom, the configuration key core.randomSeed and pyagrum.RandomGeneratorGuard therefore also make the numpy draws reproducible. Each call draws a new seed, so two calls give two different generators.

Returns:

a new numpy random generator.

Return type:

numpy.random.Generator

Example

import pyagrum as gum

gum.initRandom(42)
first = gum.randomNumpyGenerator().normal(size=3)
gum.initRandom(42)
second = gum.randomNumpyGenerator().normal(size=3)
bool((first == second).all())  # the numpy draws follow the seed of aGrUM
# True

rng = gum.randomNumpyGenerator()  # each call draws a new seed
bool((rng.normal(size=3) == gum.randomNumpyGenerator().normal(size=3)).all())
# False