Ask Your Question

Revision history [back]

This is because numpy uses the same seed that was computed before. You can reset the seed in each process:

sage: @parallel
....: def foo(i):
....:     np.random.seed()
....:     print np.random.random()
sage: list(foo(range(4)))       
0.0290924047484
0.491286471752
0.0812252231074
0.055948998056
[(((0,), {}), None),
 (((1,), {}), None),
 (((2,), {}), None),
 (((3,), {}), None)]

This is because numpy uses the same random seed that was computed before. before (and given in each subprocess). You can reset the seed in each process:process, so that they will behave independently:

sage: @parallel
....: def foo(i):
....:     np.random.seed()
....:     print np.random.random()
sage: list(foo(range(4)))       
0.0290924047484
0.491286471752
0.0812252231074
0.055948998056
[(((0,), {}), None),
 (((1,), {}), None),
 (((2,), {}), None),
 (((3,), {}), None)]