1
- .. current_module numpy.random.randomgen
1
+ .. currentmodule :: numpy.random
2
2
3
- numpy.random.randomgen
4
- ======================
3
+ numpy.random
4
+ ============
5
5
6
- This package modernizes the legacy
7
- `~numpy.random.RandomState ` object and allows changing the core random
8
- number generator (RNG). The `~numpy.random.randomgen.RandomGenerator ` can
9
- be initialized with a number of different RNGs, and exposes many different
10
- probability distributions.
6
+ A `~RandomGenerator ` can
7
+ be initialized with a number of different Random Number Generators (RNG)s, and
8
+ exposes many different probability distributions.
11
9
12
10
13
11
Quick Start
14
12
-----------
15
13
16
- By default, `generator. RandomGenerator ` uses normals provided by
14
+ By default, `RandomGenerator ` uses normals provided by
17
15
`xoroshiro128.Xoroshiro128 ` which will be faster than the legacy methods in
18
- `numpy.random `
16
+ `numpy.random.RandomState `
19
17
20
18
.. code-block :: python
21
19
22
- # As replacement for numpy.random
23
- import randomgen.generator as random
20
+ # As replacement for numpy.random.RandomState
21
+ from numpy import random
24
22
random.standard_normal()
25
23
26
- `numpy.random.randomgen.RandomGenerator ` can also be used as a replacement for
27
- `~numpy.random.RandomState `, although the random values are generated by
28
- `~numpyrandom.randomgen.xoroshiro128.Xoroshiro128 `. Since ``randomgen ``
29
- separates the `~numpy.random.randomgen.RandomGenerator ` from the RNG, it is not
30
- possible to directly seed the generator.
24
+ `RandomGenerator ` can be used as a direct replacement for
25
+ `~RandomState `, although the random values are generated by
26
+ `~xoroshiro128.Xoroshiro128 `. The `RandomGenerator ` holds an instance of a RNG.
27
+ It is accessable as ``gen.brng ``.
31
28
32
29
.. code-block :: python
33
30
34
31
# As replacement for RandomState()
35
- from randomgen import RandomGenerator
32
+ from numpy.random import RandomGenerator
36
33
rg = RandomGenerator()
37
34
rg.standard_normal()
38
35
39
36
40
- Seeds can be passed to any of the basic RNGs. Here `numpy.random.randomgen.
41
- mt19937.MT19937 ` is used and the ` ~numpy.random.randomgen.RandomGenerator ` is
42
- accessed via the attribute ` ~numpy.random.randomgen.mt19937.MT19937. generator `.
37
+ Seeds can be passed to any of the basic RNGs. Here `mt19937.MT19937 ` is used
38
+ and the `` RandomGenerator `` is accessed via the attribute ` mt19937.MT19937.
39
+ generator `.
43
40
44
41
.. code-block :: python
45
42
46
- from randomgen import MT19937
43
+ from numpy.random import MT19937
47
44
rg = MT19937(12345 ).generator
48
45
rg.standard_normal()
49
46
@@ -59,20 +56,20 @@ underlying RNG state and provides functions to produce random doubles and
59
56
random unsigned 32- and 64-bit values. The basic random generator also handles
60
57
all seeding since this varies when using alternative basic RNGs.
61
58
62
- The `random generator <~numpy.random.randomgen. RandomGenerator> ` takes the
59
+ The `random generator <~RandomGenerator> ` takes the
63
60
basic RNG-provided functions and transforms them into more useful
64
61
distributions, e.g., simulated normal random values. This structure allows
65
62
alternative basic RNGs to be used without code duplication.
66
63
67
- The `~numpy.random.randomgen. RandomGenerator ` is the user-facing object
68
- that is nearly identical to :class: `~numpy.random .RandomState `. The canonical
69
- method to initialize a generator passes a basic RNG -- `~numpy.random.
70
- randomgen.mt19937.MT19937 `, the underlying RNG in NumPy -- as the
71
- sole argument. Note that the basic RNG must be instantized.
64
+ The `` RandomGenerator ` ` is the user-facing object
65
+ that is nearly identical to :class: `~.RandomState `. The canonical
66
+ method to initialize a generator passes a basic RNG -- `~mt19937.MT19937 `, the
67
+ underlying RNG in NumPy -- as the sole argument. Note that the basic RNG must
68
+ be instantized.
72
69
73
70
.. code-block :: python
74
71
75
- from randomgen import RandomGenerator, MT19937
72
+ from numpy.random import RandomGenerator, MT19937
76
73
rg = RandomGenerator(MT19937())
77
74
rg.random_sample()
78
75
@@ -83,9 +80,8 @@ Seed information is directly passed to the basic RNG.
83
80
rg = RandomGenerator(MT19937(12345 ))
84
81
rg.random_sample()
85
82
86
- A shorthand method is also available which uses the `~numpy.random.randomgen.
87
- mt19937.MT19937.generator ` property from a basic RNG to access an embedded
88
- random generator.
83
+ A shorthand method is also available which uses the `~mt19937.MT19937.
84
+ generator ` property from a basic RNG to access an embedded random generator.
89
85
90
86
.. code-block :: python
91
87
@@ -97,11 +93,10 @@ What's New or Different
97
93
.. warning ::
98
94
99
95
The Box-Muller method used to produce NumPy's normals is no longer available
100
- in `~numpy.random.randomgen.RandomGenerator `. It is not possible to
101
- reproduce the random values using `~numpy.random.randomgen.RandomGenerator `
102
- for the normal distribution or any other distribution that
103
- relies on the normal such as the gamma or student's t. If you require
104
- backward compatibility, a legacy generator, `~numpy.random.randomgen.legacy.
96
+ in `~RandomGenerator `. It is not possible to reproduce the random values
97
+ using ``RandomGenerator `` for the normal distribution or any other
98
+ distribution that relies on the normal such as the gamma or student's t.
99
+ If you require backward compatibility, a legacy generator, `~legacy.
105
100
LegacyGenerator `, has been created which can fully reproduce the sequence
106
101
produced by NumPy.
107
102
@@ -113,18 +108,18 @@ What's New or Different
113
108
select distributions
114
109
* Optional ``out `` argument that allows existing arrays to be filled for
115
110
select distributions
116
- * `~numpy.random.randomgen. entropy.random_entropy ` provides access to the system
111
+ * `~entropy.random_entropy ` provides access to the system
117
112
source of randomness that is used in cryptographic applications (e.g.,
118
113
``/dev/urandom `` on Unix).
119
114
* All basic random generators functions can produce doubles, uint64s and
120
- uint32s via CTypes (`~numpy.random.randomgen. xoroshiro128.Xoroshiro128.ctypes `)
121
- and CFFI (:meth: `~numpy.random.randomgen. xoroshiro128.Xoroshiro128.cffi `).
115
+ uint32s via CTypes (`~xoroshiro128.Xoroshiro128.ctypes `)
116
+ and CFFI (:meth: `~xoroshiro128.Xoroshiro128.cffi `).
122
117
This allows these basic RNGs to be used in numba.
123
118
* The basic random number generators can be used in downstream projects via
124
119
:ref: `Cython <randomgen_cython >`.
125
120
* Support for Lemire’s method [Lemire ]_ of generating uniform integers on an
126
121
arbitrary interval by setting ``use_masked=True `` in
127
- `~umpy.random.randomgen.generator. RandomGenerator.randint `.
122
+ `~RandomGenerator.randint `.
128
123
129
124
130
125
See :ref: `new-or-different ` for a complete list of improvements and
@@ -146,7 +141,7 @@ generators, 'in addition' to the standard PRNG in NumPy. The included PRNGs are
146
141
147
142
* MT19937 - The standard NumPy generator. Produces identical results to NumPy
148
143
using the same seed/state. Adds a
149
- `~numpy.random.randomgen. mt19937.MT19937.jump ` function that advances the
144
+ `~mt19937.MT19937.jump ` function that advances the
150
145
generator as-if ``2**128 `` draws have been made. See `numpy.random `.
151
146
* dSFMT - SSE2 enabled versions of the MT19937 generator. Theoretically
152
147
the same, but with a different state and so it is not possible to produce a
@@ -155,24 +150,24 @@ generators, 'in addition' to the standard PRNG in NumPy. The included PRNGs are
155
150
* XoroShiro128+ - Improved version of XorShift128+ with better performance
156
151
and statistical quality. Like the XorShift generators, it can be jumped
157
152
to produce multiple streams in parallel applications. See
158
- `~numpy.random.randomgen. xoroshiro128.Xoroshiro128.jump ` for details.
153
+ `~xoroshiro128.Xoroshiro128.jump ` for details.
159
154
More information about this PRNG is available at the
160
155
`xorshift, xoroshiro and xoshiro authors' page `_.
161
156
* XorShift1024*φ - Fast fast generator based on the XSadd
162
157
generator. Supports ``jump `` and so can be used in
163
158
parallel applications. See the documentation for
164
- `~numpy.random.randomgen. xorshift1024.Xorshift1024.jump ` for details. More
159
+ `~xorshift1024.Xorshift1024.jump ` for details. More
165
160
information about these PRNGs is available at the
166
161
`xorshift, xoroshiro and xoshiro authors' page `_.
167
162
* Xorshiro256** and Xorshiro512** - The most recently introduced XOR,
168
163
shift, and rotate generator. Supports ``jump `` and so can be used in
169
164
parallel applications. See the documentation for
170
- `~numpy.random.randomgen. xoshiro256starstar.Xoshirt256StarStar.jump ` for
165
+ `~xoshiro256starstar.Xoshirt256StarStar.jump ` for
171
166
details. More information about these PRNGs is available at the
172
167
`xorshift, xoroshiro and xoshiro authors' page `_.
173
168
* PCG-64 - Fast generator that support many parallel streams and
174
169
can be advanced by an arbitrary amount. See the documentation for
175
- `~numpy.random.randomgen. pcg64.PCG64.advance `. PCG-64 has a period of
170
+ `~pcg64.PCG64.advance `. PCG-64 has a period of
176
171
:math: `2 ^{128 }`. See the `PCG author's page `_ for more details about
177
172
this class of PRNG.
178
173
* ThreeFry and Philox - counter-based generators capable of being advanced an
0 commit comments