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 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.
- 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 New call withseed
set will create a new rng sequence. Note that if you pass aGenerator
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 fromdefault_rng()
.