I want to generate a random seed in a predictable way.
I was hoping to do this
seed = 12345
prng_0 = random.Random(seed)
prng_1 = random.Random(prng_0.rand_int(0))
There, 0 is the lower bound, but it turns out I need to give it an upper bound as well. I don't want to set a fixed upper bound.
If you are curious about my reason, I'm doing this because I need reproducibility when testing. Namely, this is a function receiving a seed and building its prng, prng_0, then calling multiple times another function that needs to receive a different seed every time.
def funct_a(seed=None):
prng_1 = random.Random(seed)
print(prng_1.random())
def funct_b(seed=None):
prng_0 = random.Random(seed)
for i in range(0, 5):
seed = prng_0.randint(0) # not working, needs upper bound
funct_a(seed)
funct_b(12345) # test call
Aucun commentaire:
Enregistrer un commentaire