Skip to content

Commit c17778f

Browse files
authored
Merge pull request #87 from bashtage/fix-multithead-example
DOC: Fix bug in Multithreaded PRNG example
2 parents 735986c + 015e1e8 commit c17778f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

doc/source/multithreading.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ same seed will produce the same outputs.
2828
threads = multiprocessing.cpu_count()
2929
self.threads = threads
3030

31-
self._random_states = [rs]
32-
for _ in range(1, threads):
31+
self._random_states = []
32+
for _ in range(0, threads-1):
3333
_rs = randomstate.prng.xorshift1024.RandomState()
34-
rs.jump()
3534
_rs.set_state(rs.get_state())
3635
self._random_states.append(_rs)
36+
rs.jump()
37+
self._random_states.append(rs)
3738

3839
self.n = n
3940
self.executor = concurrent.futures.ThreadPoolExecutor(threads)
@@ -68,12 +69,13 @@ same seed will produce the same outputs.
6869
....: if threads is None:
6970
....: threads = multiprocessing.cpu_count()
7071
....: self.threads = threads
71-
....: self._random_states = [rs]
72-
....: for _ in range(1, threads):
72+
....: self._random_states = []
73+
....: for _ in range(0, threads-1):
7374
....: _rs = randomstate.prng.xorshift1024.RandomState()
74-
....: rs.jump()
7575
....: _rs.set_state(rs.get_state())
7676
....: self._random_states.append(_rs)
77+
....: rs.jump()
78+
....: self._random_states.append(rs)
7779
....: self.n = n
7880
....: self.executor = concurrent.futures.ThreadPoolExecutor(threads)
7981
....: self.values = np.empty(n)

0 commit comments

Comments
 (0)