@@ -16,7 +16,7 @@ should be used. This example shows how many streams can be created by
16
16
passing in different index values in the second input while using the
17
17
same seed in the first.
18
18
19
- ::
19
+ .. code-block :: python
20
20
21
21
from randomstate.entropy import random_entropy
22
22
import randomstate.prng.pcg64 as pcg64
@@ -32,6 +32,9 @@ same seed in the first.
32
32
Jump/Advance the PRNG state
33
33
---------------------------
34
34
35
+ Jump
36
+ ****
37
+
35
38
``jump `` advances the state of the PRNG *as-if * a large number of random
36
39
numbers have been drawn. The specific number of draws varies by PRNG, and
37
40
ranges from :math: `2 ^{64 }` to :math: `2 ^{512 }`. Additionally, the *as-if *
@@ -55,7 +58,7 @@ are listed below.
55
58
``jump `` can be used to produce long blocks which should be long enough to not
56
59
overlap.
57
60
58
- ::
61
+ .. code-block :: python
59
62
60
63
from randomstate.entropy import random_entropy
61
64
import randomstate.prng.xorshift1024 as xorshift1024
@@ -70,7 +73,47 @@ overlap.
70
73
blocks.append(block)
71
74
72
75
76
+ Advance
77
+ *******
73
78
``advance `` can be used to jump the state an arbitrary number of steps, and so
74
79
is a more general approach than ``jump ``. Only ``pcg32 `` and ``pcg64 ``
75
80
support ``advance ``, and since these also support independent streams, it is
76
81
not usually necessary to use ``advance ``.
82
+
83
+ Advancing a PRNG updates the underlying PRNG state as-if a given number of
84
+ calls to the underlying PRNG have been made. In general there is not a
85
+ one-to-one relationship between the number output random values from a
86
+ particular distribution and the number of draws from the core PRNG.
87
+ This occurs for two reasons:
88
+
89
+ * The random values are simulated using a rejection-based method
90
+ and so, on average, more than one value from the underlying
91
+ PRNG is required to generate an single draw.
92
+ * The number of bits required to generate a simulated value
93
+ differs from the number of bits generated by the underlying
94
+ PRNG. For example, two 16-bit integer values can be simulated
95
+ from a single draw of a 32-bit PRNG.
96
+
97
+ Advancing the PRNG state resets any pre-computed random numbers. This is
98
+ required to ensure exact reproducibility.
99
+
100
+ This example uses ``advance `` to advance a ``pcg64 `` generator 2 ** 127
101
+ steps to set a sequence of random number generators.
102
+
103
+ .. code-block :: python
104
+
105
+ import randomstate.prng.pcg64 as pcg64
106
+ rs = pcg64.RandomState()
107
+ rs_gen = pcg64.RandomState()
108
+ rs_gen.set_state(rs.get_state())
109
+
110
+ advance = 2 ** 127
111
+ rngs = [rs]
112
+ for _ in range (9 ):
113
+ rs_gen.advance(advance)
114
+ rng = pcg64.RandomState()
115
+ rng.set_state(rs_gen.get_state())
116
+ rngs.append(rng)
117
+
118
+ .. end block
119
+
0 commit comments