You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Keep in mind, that locale-independent data providers will work
only with keyword-only arguments since version 5.0.0.
:param seed: Seed for random.
When set to `None` the current system time is used.
"""
self.seed=seed
self.random=random
ifseedisnotNone:
self.reseed(seed)
defreseed(self, seed: Seed=None) ->None:
"""Reseed the internal random generator.
In case we use the default seed, we need to create a per instance
random generator, in this case two providers with the same seed
will always return the same values.
:param seed: Seed for random.
When set to `None` the current system time is used.
"""
ifself.randomisrandom:
self.random=Random()
self.seed=seed
self.random.seed(self.seed)
Generic overrides .reseed() and reseeds its sub-providers. However, it doesn't call super().reseed(seed) which means that it never creates its own per-instance random, nor does it reseed it. This means that the random instance on Generic cannot be used reproducibly.
BaseProvider.reseed() should always be called from BaseProvider.__init__(), even when seed is None to ensure that a per-instance random is added. (I don't see why you wouldn't always want this.) And would it then make sense to always do self.random = Random() in BaseProvider.__init__() and not in BaseProvider.reseed()?
Bug report
What's wrong
BaseProvider
calls.reseed()
from.__init__()
but only whenseed is not None
.mimesis/mimesis/providers/base.py
Lines 24 to 53 in 01a29e7
Generic
overrides.reseed()
and reseeds its sub-providers. However, it doesn't callsuper().reseed(seed)
which means that it never creates its own per-instancerandom
, nor does it reseed it. This means that the random instance onGeneric
cannot be used reproducibly.mimesis/mimesis/providers/generic.py
Lines 113 to 125 in 01a29e7
How is that should be
BaseProvider.reseed()
should always be called fromBaseProvider.__init__()
, even whenseed
isNone
to ensure that a per-instancerandom
is added. (I don't see why you wouldn't always want this.) And would it then make sense to always doself.random = Random()
inBaseProvider.__init__()
and not inBaseProvider.reseed()
?Generic.reseed()
should callsuper().reseed(seed)
.The text was updated successfully, but these errors were encountered: