@@ -67,101 +67,89 @@ python setup.py install
67
67
68
68
## Building for Testing Purposes
69
69
70
- There are two options. The first will build a library for xorshift128 called
71
- ` core_rng ` .
70
+ This command will build a single module containining xorshift128 called
71
+ ` interface ` .
72
72
73
73
``` bash
74
74
cd randomstate
75
75
python setup-basic.py build_ext --inplace
76
76
```
77
77
78
- The second will build a numberfiles, one for each RNG.
79
-
80
- ``` bash
81
- cd randomstate
82
- python setup-all.py build_ext --inplace
83
- ```
84
-
85
78
## Using
86
- If you installed,
79
+
80
+ The separate generators are importable from ` randomstate.prng ` .
87
81
88
82
``` python
89
- import randomstate.xorshift128
90
- rs = randomstate.xorshift128.RandomState()
83
+ import randomstate
84
+ rs = randomstate.prng. xorshift128.RandomState()
91
85
rs.random_sample(100 )
92
86
93
- import randomstate.pcg64
94
- rs = randomstate.pcg64.RandomState()
87
+ rs = randomstate.prng.pcg64.RandomState()
95
88
rs.random_sample(100 )
96
89
97
90
# Identical to NumPy
98
- import randomstate.mt19937
99
- rs = randomstate.mt19937.RandomState()
91
+ rs = randomstate.prng.mt19937.RandomState()
100
92
rs.random_sample(100 )
101
93
```
102
94
103
- If you use ` setup-basic.py ` ,
95
+ Like NumPy, ` randomstate ` also exposes a single instance of the ` mt19937 `
96
+ generator directly at the moduel level so that commands like
104
97
105
98
``` python
106
- import core_rng
107
-
108
- rs = core_rng.RandomState()
109
- rs.random_sample(100 )
99
+ import randomstate
100
+ randomstate.standard_normal()
101
+ randomstate.exponential(1.0 , 1.0 , size = 10 )
110
102
```
111
103
112
- If you use ` setup-all.py ` ,
113
-
114
- ``` python
115
- import mt19937, pcg32, xorshift128
104
+ will work.
116
105
117
- rs = mt19937.RandomState()
118
- rs.random_sample(100 )
106
+ If you use ` setup-basic.py ` ,
119
107
120
- rs = pcg32.RandomState()
121
- rs.random_sample( 100 )
108
+ ``` python
109
+ import interface
122
110
123
- rs = xorshift129 .RandomState()
111
+ rs = interface .RandomState()
124
112
rs.random_sample(100 )
125
113
```
126
114
127
115
## License
128
116
Standard NCSA, plus sub licenses for components.
129
117
130
118
## Performance
131
- Performance is promising. Some early numbers:
119
+ Performance is promising, and even the mt19937 seems to be faster than NumPy's mt19937.
132
120
133
121
```
134
- Time to produce 1,000,000 Uniforms
122
+ Time to produce 1,000,000 Standard normals
135
123
************************************************************
136
- numpy-random-random_sample 13.68 ms
137
- randomstate-mlfg_1279_861-random_sample 6.64 ms
138
- randomstate-mrg32k3a-random_sample 37.87 ms
139
- randomstate-mt19937-random_sample 13.33 ms
140
- randomstate-pcg32-random_sample 10.20 ms
141
- randomstate-pcg64-random_sample 7.83 ms
142
- randomstate-xorshift1024-random_sample 6.20 ms
143
- randomstate-xorshift128-random_sample 5.49 ms
144
-
145
- Uniforms per second
124
+ numpy-random-standard_normal 58.34 ms
125
+ randomstate.prng -mlfg_1279_861-standard_normal 46.20 ms
126
+ randomstate.prng -mrg32k3a-standard_normal 75.95 ms
127
+ randomstate.prng -mt19937-standard_normal 52.68 ms
128
+ randomstate.prng -pcg32-standard_normal 48.38 ms
129
+ randomstate.prng -pcg64-standard_normal 46.27 ms
130
+ randomstate.prng -xorshift1024-standard_normal 45.53 ms
131
+ randomstate.prng -xorshift128-standard_normal 45.57 ms
132
+
133
+ Standard normals per second
146
134
************************************************************
147
- numpy-random-random_sample 73.11 million
148
- randomstate-mlfg_1279_861-random_sample 150.71 million
149
- randomstate-mrg32k3a-random_sample 26.41 million
150
- randomstate-mt19937-random_sample 75.03 million
151
- randomstate-pcg32-random_sample 98.00 million
152
- randomstate-pcg64-random_sample 127.77 million
153
- randomstate-xorshift1024-random_sample 161.39 million
154
- randomstate-xorshift128-random_sample 182.29 million
135
+ numpy-random-standard_normal 17.14 million
136
+ randomstate.prng -mlfg_1279_861-standard_normal 21.65 million
137
+ randomstate.prng -mrg32k3a-standard_normal 13.17 million
138
+ randomstate.prng -mt19937-standard_normal 18.98 million
139
+ randomstate.prng -pcg32-standard_normal 20.67 million
140
+ randomstate.prng -pcg64-standard_normal 21.61 million
141
+ randomstate.prng -xorshift1024-standard_normal 21.96 million
142
+ randomstate.prng -xorshift128-standard_normal 21.94 million
155
143
156
144
Speed-up relative to NumPy
157
145
************************************************************
158
- randomstate-mlfg_1279_861-random_sample 106.1 %
159
- randomstate-mrg32k3a-random_sample -63.9 %
160
- randomstate-mt19937-random_sample 2.6 %
161
- randomstate-pcg32-random_sample 34.0 %
162
- randomstate-pcg64-random_sample 74.8 %
163
- randomstate-xorshift1024-random_sample 120.7 %
164
- randomstate-xorshift128-random_sample 149.3 %
146
+ randomstate.prng -mlfg_1279_861-standard_normal 26.3 %
147
+ randomstate.prng -mrg32k3a-standard_normal -23.2 %
148
+ randomstate.prng -mt19937-standard_normal 10.8 %
149
+ randomstate.prng -pcg32-standard_normal 20.6 %
150
+ randomstate.prng -pcg64-standard_normal 26.1 %
151
+ randomstate.prng -xorshift1024-standard_normal 28.1 %
152
+ randomstate.prng -xorshift128-standard_normal 28.0 %
165
153
166
154
--------------------------------------------------------------------------------
167
155
```
@@ -170,8 +158,12 @@ randomstate-xorshift128-random_sample 149.3%
170
158
171
159
### New Functions
172
160
161
+ * ` random_entropy ` - Read from the system entropy provider, which is commonly
162
+ used in cryptographic applications
173
163
* ` random_uintegers ` - unsigned integers ` [0, 2**64-1] `
174
164
* ` jump ` - Jumps RNGs that support it. ` jump ` moves the state a great
175
165
distance. _ Only available if supported by the RNG._
176
166
* ` advance ` - Advanced the core RNG 'as-if' a number of draws were made,
177
167
without actually drawing the numbers. _ Only available if supported by the RNG._
168
+
169
+ ### New Functions
0 commit comments