I previously asked Repeatedly run a function in parallel on how to run a function in parallel. The function that I am wanting to run has a stochastic element, where random integers are drawn.
When I use the code in that answer it returns repeated numbers within one process (and also between runs if I add an outer loop to repeat the process). For example,
import numpy as np
from multiprocessing.pool import Pool
def f(_):
x = np.random.uniform()
return x*x
if __name__ == "__main__":
processes = 3
p = Pool(processes)
print(p.map(f, range(6)))
returns
[0.8484870744666029, 0.8484870744666029, 0.04019012715175054, 0.04019012715175054, 0.7741414835156634, 0.7741414835156634]
Another run may give
[0.17390735240615365, 0.17390735240615365, 0.5188673758527017, 1.308159884267618e-08, 0.09140498447418667, 0.021537291489524404]
It seems as if there is some internal seed that is being used -- how can I generate random numbers similar to what would be returned from np.random.uniform(size=6)
please?