@@ -22,34 +22,44 @@ Since Numpy version 1.17.0 the Generator can be initialized with a
2222number of different BitGenerators. It exposes many different probability
2323distributions. See `NEP 19 <https://www.numpy.org/neps/
2424nep-0019-rng-policy.html> `_ for context on the updated random Numpy number
25- routines. The legacy `. RandomState ` random number routines are still
25+ routines. The legacy `RandomState ` random number routines are still
2626available, but limited to a single BitGenerator.
2727
28- For convenience and backward compatibility, a single `~. RandomState `
28+ For convenience and backward compatibility, a single `RandomState `
2929instance's methods are imported into the numpy.random namespace, see
3030:ref: `legacy ` for the complete list.
3131
32+ .. _random-quick-start :
33+
3234Quick Start
3335-----------
3436
35- By default, `~Generator ` uses bits provided by `PCG64 ` which
36- has better statistical properties than the legacy mt19937 random
37- number generator in `~.RandomState `.
37+ Call `default_rng ` to get a new instance of a `Generator `, then call its
38+ methods to obtain samples from different distributions. By default,
39+ `Generator ` uses bits provided by `PCG64 ` which has better statistical
40+ properties than the legacy `MT19937 ` used in `RandomState `.
3841
3942.. code-block :: python
4043
41- # Uses the old numpy.random.RandomState
44+ # Do this
45+ from numpy.random import default_rng
46+ rng = default_rng()
47+ vals = rng.standard_normal(10 )
48+ more_vals = rng.standard_normal(10 )
49+
50+ # instead of this
4251 from numpy import random
43- random.standard_normal()
52+ vals = random.standard_normal(10 )
53+ more_vals = random.standard_normal(10 )
4454
45- `~ Generator ` can be used as a replacement for `~. RandomState `. Both class
46- instances now hold a internal `BitGenerator ` instance to provide the bit
55+ `Generator ` can be used as a replacement for `RandomState `. Both class
56+ instances hold a internal `BitGenerator ` instance to provide the bit
4757stream, it is accessible as ``gen.bit_generator ``. Some long-overdue API
4858cleanup means that legacy and compatibility methods have been removed from
49- `~. Generator `
59+ `Generator `
5060
5161=================== ============== ============
52- `~. RandomState ` ` ~. Generator ` Notes
62+ `RandomState ` ` Generator ` Notes
5363------------------- -------------- ------------
5464``random_sample ``, ``random `` Compatible with `random.random `
5565``rand ``
@@ -58,21 +68,12 @@ cleanup means that legacy and compatibility methods have been removed from
5868``random_integers ``
5969------------------- -------------- ------------
6070``tomaxint `` removed Use ``integers(0, np.iinfo(np.int_).max, ``
61- ``endpoint=False) ``
71+ ``endpoint=False) ``
6272------------------- -------------- ------------
63- ``seed `` removed Use `~. SeedSequence.spawn `
73+ ``seed `` removed Use `SeedSequence.spawn `
6474=================== ============== ============
6575
66- See `new-or-different ` for more information
67-
68- .. code-block :: python
69-
70- # As replacement for RandomState(); default_rng() instantiates Generator with
71- # the default PCG64 BitGenerator.
72- from numpy.random import default_rng
73- rg = default_rng()
74- rg.standard_normal()
75- rg.bit_generator
76+ See :ref: `new-or-different ` for more information
7677
7778Something like the following code can be used to support both ``RandomState ``
7879and ``Generator ``, with the understanding that the interfaces are slightly
@@ -87,9 +88,9 @@ different
8788 a = rg_integers(1000 )
8889
8990 Seeds can be passed to any of the BitGenerators. The provided value is mixed
90- via `~. SeedSequence ` to spread a possible sequence of seeds across a wider
91- range of initialization states for the BitGenerator. Here `~. PCG64 ` is used and
92- is wrapped with a `~. Generator `.
91+ via `SeedSequence ` to spread a possible sequence of seeds across a wider
92+ range of initialization states for the BitGenerator. Here `PCG64 ` is used and
93+ is wrapped with a `Generator `.
9394
9495.. code-block :: python
9596
@@ -100,7 +101,7 @@ is wrapped with a `~.Generator`.
100101 Introduction
101102------------
102103The new infrastructure takes a different approach to producing random numbers
103- from the `~. RandomState ` object. Random number generation is separated into
104+ from the `RandomState ` object. Random number generation is separated into
104105two components, a bit generator and a random generator.
105106
106107The `BitGenerator ` has a limited set of responsibilities. It manages state
@@ -113,8 +114,8 @@ distributions, e.g., simulated normal random values. This structure allows
113114alternative bit generators to be used with little code duplication.
114115
115116The `Generator ` is the user-facing object that is nearly identical to
116- `. RandomState `. The canonical method to initialize a generator passes a
117- `~. PCG64 ` bit generator as the sole argument.
117+ `RandomState `. The canonical method to initialize a generator passes a
118+ `PCG64 ` bit generator as the sole argument.
118119
119120.. code-block :: python
120121
@@ -139,9 +140,9 @@ What's New or Different
139140 The Box-Muller method used to produce NumPy's normals is no longer available
140141 in `Generator `. It is not possible to reproduce the exact random
141142 values using Generator for the normal distribution or any other
142- distribution that relies on the normal such as the `. RandomState.gamma ` or
143- `. RandomState.standard_t `. If you require bitwise backward compatible
144- streams, use `. RandomState `.
143+ distribution that relies on the normal such as the `RandomState.gamma ` or
144+ `RandomState.standard_t `. If you require bitwise backward compatible
145+ streams, use `RandomState `.
145146
146147* The Generator's normal, exponential and gamma functions use 256-step Ziggurat
147148 methods which are 2-10 times faster than NumPy's Box-Muller or inverse CDF
@@ -152,20 +153,20 @@ What's New or Different
152153* Optional ``out `` argument that allows existing arrays to be filled for
153154 select distributions
154155* All BitGenerators can produce doubles, uint64s and uint32s via CTypes
155- (`~. PCG64.ctypes `) and CFFI (`~. PCG64.cffi `). This allows the bit generators
156+ (`PCG64.ctypes `) and CFFI (`PCG64.cffi `). This allows the bit generators
156157 to be used in numba.
157158* The bit generators can be used in downstream projects via
158159 :ref: `Cython <random_cython >`.
159- * `~. Generator.integers ` is now the canonical way to generate integer
160+ * `Generator.integers ` is now the canonical way to generate integer
160161 random numbers from a discrete uniform distribution. The ``rand `` and
161- ``randn `` methods are only available through the legacy `~. RandomState `.
162+ ``randn `` methods are only available through the legacy `RandomState `.
162163 The ``endpoint `` keyword can be used to specify open or closed intervals.
163164 This replaces both ``randint `` and the deprecated ``random_integers ``.
164- * `~. Generator.random ` is now the canonical way to generate floating-point
165- random numbers, which replaces `. RandomState.random_sample `,
166- `. RandomState.sample `, and `. RandomState.ranf `. This is consistent with
165+ * `Generator.random ` is now the canonical way to generate floating-point
166+ random numbers, which replaces `RandomState.random_sample `,
167+ `RandomState.sample `, and `RandomState.ranf `. This is consistent with
167168 Python's `random.random `.
168- * All BitGenerators in numpy use `~ SeedSequence ` to convert seeds into
169+ * All BitGenerators in numpy use `SeedSequence ` to convert seeds into
169170 initialized states.
170171
171172See :ref: `new-or-different ` for a complete list of improvements and
@@ -202,8 +203,9 @@ Features
202203 c-api
203204 Examples of using Numba, Cython, CFFI <extending >
204205
205- Original Source
206- ~~~~~~~~~~~~~~~
206+ Original Source of the Generator and BitGenerators
207+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
207208
208209This package was developed independently of NumPy and was integrated in version
2092101.17.0. The original repo is at https://github.com/bashtage/randomgen.
211+
0 commit comments