Assume I have a function that requires random number (noise) like:
@parallel
def foo(i):
print np.random.random()
4 sequential runs yield desired output:
for i in range(4):
foo(i)
0.961718217227
0.909042125122
0.736138778296
0.149902522071
But the parallel run calculates only one random value:
list(foo(range(4)))
0.633760965726
0.633760965726
0.633760965726
0.633760965726
[(((0),{}),None),(((2),{}),None),(((1),{}),None),(((3),{}),None)]
How do I properly generate random values from within parallel function?