-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix typos and wrap length
- Loading branch information
Showing
2 changed files
with
19 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters