Skip to content

Commit

Permalink
DOC: Correct doc errors
Browse files Browse the repository at this point in the history
Fix typos and wrap length
  • Loading branch information
bashtage committed Aug 11, 2022
1 parent cf3ca15 commit 962535f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
33 changes: 17 additions & 16 deletions doc/release/upcoming_changes/21976.new_feature.rst
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
The bit generator underlying the singleton RandomState can be changed
---------------------------------------------------------------------
The singleton ``RandomState`` instance exposed in the ``numpy.random`` module
id initialized using system-provided entropy with the ``MT19937` bit generator.
The function ``set_bit_generator`` allows the default bit generator to be
replaced with a user-provided bit generator. This function has been introduced to
provide a method allowing seemless integration of a high-quality, modern bit generator
in new code with existing code that makes use of the singleton-provided random
variate generating functions. The companion function ``get_bit_generator`` returns the current bit generator
being used by the singleton ``RandomState``. This is provided to simplify restoring
is initialized at startup with the ``MT19937` bit generator. The function new ``set_bit_generator`` allows the default bit generator to be
replaced with a user-provided bit generator. This function has been introduced
to provide a method allowing seamless integration of a high-quality, modern bit
generator in new code with existing code that makes use of the
singleton-provided random variate generating functions. The companion function
``get_bit_generator`` returns the current bit generator being used by the
singleton ``RandomState``. This is provided to simplify restoring
the original source of randomness if required.

The preferred method to generate reproducible random numbers is to use a modern
bit generator in an instance of ``Generator``. The function ``default_rng``
simplifies instantization.

>>> rg = np.random.default_rng(3728973198)
>>> rg.random()
>>> rg = np.random.default_rng(3728973198)
>>> rg.random()

The same bit generator can then shared with the singleton instance so that
calling functions in the ``random`` module will use the same bit generator.
The same bit generator can then be shared with the singleton instance so that
calling functions in the ``random`` module will use the same bit
generator.

>>> orig_bit_gen = np.random.get_bit_generator()
>>> np.random.set_bit_generator(rg.bit_generator)
>>> np.random.normal()
>>> orig_bit_gen = np.random.get_bit_generator()
>>> np.random.set_bit_generator(rg.bit_generator)
>>> np.random.normal()

The swap is permanent (until reversed) and so any call to functions
in the ``random`` module will use the new bit generator. The orginal
in the ``random`` module will use the new bit generator. The original
can be restored if required for code to run correctly.

>>> np.random.set_bit_generator(orig_bit_gen)
>>> np.random.set_bit_generator(orig_bit_gen)
4 changes: 2 additions & 2 deletions numpy/random/mtrand.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4749,7 +4749,7 @@ def get_bit_generator():
Notes
-----
The singleton RandomState provides the random variate generators in the
NumPy random namespace. This function, and its counterpart set method,
``numpy.random`` namespace. This function, and its counterpart set method,
provides a path to hot-swap the default MT19937 bit generator with a
user provided alternative. These function are intended to provide
a continuous path where a single underlying bit generator can be
Expand All @@ -4775,7 +4775,7 @@ def set_bit_generator(bitgen):
Notes
-----
The singleton RandomState provides the random variate generators in the
NumPy random namespace. This function, and its counterpart get method,
``numpy.random``namespace. This function, and its counterpart get method,
provides a path to hot-swap the default MT19937 bit generator with a
user provided alternative. These function are intended to provide
a continuous path where a single underlying bit generator can be
Expand Down

0 comments on commit 962535f

Please sign in to comment.