Skip to content

Commit 95a354f

Browse files
bashtageSheppard, Kevin
authored andcommitted
DOC: Add PRNG implementation details
Add details of all PRNG implementaions as well as state info [skip ci]
1 parent f443577 commit 95a354f

File tree

8 files changed

+79
-6
lines changed

8 files changed

+79
-6
lines changed

compute_mod3.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pandas as pd
2+
import numpy as np
3+
import seaborn as sns
4+
5+
sns.mpl.rcParams['figure.figsize'] = [12, 8]
6+

randomstate/shims/dSFMT/dSFMT.pxi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ segments come from the same sequence.
140140
rs[i].jump(i)
141141
142142
**State and Seeding**
143+
143144
The ``dsfmt.RandomState`` state vector consists of a 764 element array of
144145
32-bit unsigned integers plus a single integer value between 0 and 382
145146
indicating the current position within the main array. The implementation

randomstate/shims/mlfg-1279-861/mlfg-1279-861.pxi

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ integers as well as a two 32-bit integers representing the location in the
9494
state array of the current and lagged values.
9595
9696
**State and Seeding**
97-
The ``dsfmt.mlfg_1279_861`` state vector consists of a 1279 element array of
98-
64-bit unsigned integers plus a two integers value between 0 and 1278
99-
indicating the current position and the lagged value within the main array
100-
required to produce the next random.
10197
102-
``dsfmt.mlfg_1279_861`` is seeded using either a single 64-bit unsigned integer
98+
The ``mlfg_1279_861.RandomState`` state vector consists of a 1279 element array
99+
of 64-bit unsigned integers plus a two integers value between 0 and 1278
100+
indicating the current position and the position of the lagged value within
101+
the main array required to produce the next random. All elements of the 1279
102+
element state array must be odd.
103+
104+
``mlfg_1279_861.RandomState`` is seeded using either a single 64-bit unsigned integer
103105
or a vector of 64-bit unsigned integers. In either case the input seed is
104106
used as an input (or inputs) for another simple random number generator,
105107
Splitmix64, and the output of this PRNG function is used as the initial state.
@@ -108,5 +110,5 @@ the possible initial state values. When using an array, the SplitMix64 state
108110
for producing the ith component of the initial state is XORd with the ith
109111
value of the seed array until the seed array is exhausted. When using an array
110112
the initial state for the SplitMix64 state is 0 so that using a single element
111-
array and using a single scalar value will produce the same initial state.
113+
array and using the same value as a scalar will produce the same initial state.
112114
"""

randomstate/shims/mrg32k3a/mrg32k3a.pxi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ seed to ensure that the segments come from the same sequence.
161161
>>> for i in range(10):
162162
rs[i].jump(i)
163163
164+
**State and Seeding**
165+
166+
The ``mrg32k3a.RandomState`` state vector consists of a 6 element array
167+
of 64-bit signed integers plus a single integers value between 0 and 2
168+
indicating the current position within the state vector. The first three
169+
elements of the state vector are in [0, 4294967087) and the second 3 are
170+
in [0, 4294944443).
171+
172+
``mrg32k3a.RandomState`` is seeded using either a single 64-bit unsigned integer
173+
or a vector of 64-bit unsigned integers. In either case the input seed is
174+
used as an input (or inputs) for another simple random number generator,
175+
Splitmix64, and the output of this PRNG function is used as the initial state.
176+
Using a single 64-bit value for the seed can only initialize a small range of
177+
the possible initial state values. When using an array, the SplitMix64 state
178+
for producing the ith component of the initial state is XORd with the ith
179+
value of the seed array until the seed array is exhausted. When using an array
180+
the initial state for the SplitMix64 state is 0 so that using a single element
181+
array and using the same value as a scalar will produce the same initial state.
164182
165183
References
166184
----------

randomstate/shims/pcg-32/pcg-32.pxi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ produce non-overlapping sequences.
102102
*Note*: Due to the limited period of ``pcg32.RandomState`` using ``advance``
103103
in parallel applications is not recommended.
104104
105+
**State and Seeding**
106+
107+
The ``pcg32.RandomState`` state vector consists of 2 unsigned 64 bit values.
108+
``pcg32.RandomState` is seeded using a single 64-bit unsigned integer.
109+
In addition, a second 64-bit unsigned integer is used to set the stream.
110+
105111
References
106112
----------
107113
.. [1] "PCG, A Family of Better Random Number Generators",

randomstate/shims/pcg-64/pcg-64-docstring.pxi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ produce non-overlapping sequences.
6262
>>> for i in range(10):
6363
rs[i].advance(i * 2**64)
6464
65+
**State and Seeding**
66+
67+
The ``pcg64.RandomState`` state vector consists of 2 unsigned 128 bit values,
68+
which are represented externally as python longs (2.x) or ints (Python 3+).
69+
``pcg64.RandomState` is seeded using a single 128-bit unsigned integer
70+
(Python long/int). In addition, a second 128-bit unsigned integer is used
71+
to set the stream.
72+
6573
References
6674
----------
6775
.. [1] "PCG, A Family of Better Random Number Generators",

randomstate/shims/xorshift1024/xorshift1024.pxi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ seed to ensure that the segments come from the same sequence.
102102
>>> for i in range(10):
103103
rs[i].jump(i)
104104
105+
**State and Seeding**
106+
107+
The ``xorshift1024.RandomState`` state vector consists of a 16 element array
108+
of 64-bit unsigned integers.
109+
110+
``xorshift1024.RandomState`` is seeded using either a single 64-bit unsigned integer
111+
or a vector of 64-bit unsigned integers. In either case the input seed is
112+
used as an input (or inputs) for another simple random number generator,
113+
Splitmix64, and the output of this PRNG function is used as the initial state.
114+
Using a single 64-bit value for the seed can only initialize a small range of
115+
the possible initial state values. When using an array, the SplitMix64 state
116+
for producing the ith component of the initial state is XORd with the ith
117+
value of the seed array until the seed array is exhausted. When using an array
118+
the initial state for the SplitMix64 state is 0 so that using a single element
119+
array and using the same value as a scalar will produce the same initial state.
120+
105121
References
106122
----------
107123
.. [1] "xorshift*/xorshift+ generators and the PRNG shootout",

randomstate/shims/xorshift128/xorshift128.pxi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ seed to ensure that the segments come from the same sequence.
9898
>>> for i in range(10):
9999
rs[i].jump(i)
100100
101+
**State and Seeding**
102+
103+
The ``xorshift128.RandomState`` state vector consists of a 2 element array
104+
of 64-bit unsigned integers.
105+
106+
``xorshift128.RandomState`` is seeded using either a single 64-bit unsigned integer
107+
or a vector of 64-bit unsigned integers. In either case the input seed is
108+
used as an input (or inputs) for another simple random number generator,
109+
Splitmix64, and the output of this PRNG function is used as the initial state.
110+
Using a single 64-bit value for the seed can only initialize a small range of
111+
the possible initial state values. When using an array, the SplitMix64 state
112+
for producing the ith component of the initial state is XORd with the ith
113+
value of the seed array until the seed array is exhausted. When using an array
114+
the initial state for the SplitMix64 state is 0 so that using a single element
115+
array and using the same value as a scalar will produce the same initial state.
116+
101117
References
102118
----------
103119
.. [1] "xorshift*/xorshift+ generators and the PRNG shootout",

0 commit comments

Comments
 (0)