jeudi 22 avril 2021

General random seed for a script with multiple random number generators(rng)?

I am developing an agent-based model in python where I have a population of items that can divide or die. In one run of my script I use several random number generators. A simplified example:

import numpy as np
#Division and death probability 
division_prob = 0.5 
death_prob = 0.3
population = [item0,item1,item2,...,item100] 
for item in population:
    #division
    if np.random.uniform(0,1) < division_prob:
        population.append(item.copy())
    #death
    if np.random.uniform(0,1) < death_prob:
        population.remove(item)

In this case if I give a seed for the rng, then I always obtain the same random number for all the items. Is there a way to have like a general random seed for the script (so I can run the script again and get the same results) and yet inside the loops I can get different random numbers for each item?

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire