Routines to set common Generator (cmomy.random)#

cmomy is setup to use numpy.random.Generator objects, as opposed to using the “classic” numpy.random interface. For simplicity, you can set a shared Generator object using the routine default_rng(). You can set the seed of this random number generator (rng) used across routines. You can also pass Generator objects to routines that require random number.

Functions:

set_internal_rng(rng)

Set the internal random number Generator.

get_internal_rng()

Get the internal random number Generator.

default_rng([seed])

Get default internal random number generator.

validate_rng(rng[, seed])

Decide whether to use passed Generator or that from default_rng().

cmomy.random.set_internal_rng(rng)[source]#

Set the internal random number Generator.

The function default_rng() will call rng if called with a new seed (or when called the first time). However, if want to override the internal rng, you can use this function.

cmomy.random.get_internal_rng()[source]#

Get the internal random number Generator.

cmomy.random.default_rng(seed=None)[source]#

Get default internal random number generator.

Parameters:

seed (Union[int, Sequence[int], SeedSequence, BitGenerator, Generator, None], default: None) – If specified, set the internal seed to this value. If pass in a numpy.random.Generator, return that object.

Returns:

Generator – If called with seed=None (default), return the previously created rng (if already created). This means you can call default_rng(seed=...) and subsequent calls of form default_rng() or default_rng(None) will continue rng sequence from first call with seed=.... If New call with seed set will create a new rng sequence. Note that if you pass a Generator for seed, that object will be returned, but in this case, the internal generator will not be altered.

cmomy.random.validate_rng(rng, seed=None)[source]#

Decide whether to use passed Generator or that from default_rng().

Parameters:
Returns:

Generator