Internal numpy.random.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 the internal random number |
Get the internal random number |
|
|
Get default internal random number generator. |
|
Decide whether to use passed |
- 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.default_rng(seed=None)[source]#
Get default internal random number generator.
This is a shared default random number generator. Calling it with a new seed will create a new shared random generator. To create a one off generator, use
numpy.random.default_rng()- Parameters:
seed (
Union[int,Sequence[int],SeedSequence,BitGenerator,Generator,None], default:None) – If specified, set the internal seed to this value. If pass in anumpy.random.Generator, return that object.- Returns:
Generator– If called withseed=None(default), return the previously created rng (if already created). This means you can calldefault_rng(seed=...)and subsequent calls of formdefault_rng()ordefault_rng(None)will continue rng sequence from first call withseed=.... If called withseed, create a new rng sequence. Note that if you pass aGeneratorfor seed, that object will be returned, but in this case, the internal generator will not be altered.
See also
- cmomy.random.validate_rng(rng)[source]#
Decide whether to use passed
Generatoror that fromdefault_rng().- Parameters:
rng (
Union[int,Sequence[int],SeedSequence,BitGenerator,Generator,None]) – IfNone, usedefault_rng(). Otherwise, try to returnnp.random.default_rng(rng). If this fails, just return rng- Returns: