Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-101100: Fix Sphinx warnings in library/random.rst #112981

Merged
merged 12 commits into from
Dec 28, 2023
47 changes: 36 additions & 11 deletions Doc/library/random.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Bookkeeping functions

.. versionchanged:: 3.11
The *seed* must be one of the following types:
*NoneType*, :class:`int`, :class:`float`, :class:`str`,
``None``, :class:`int`, :class:`float`, :class:`str`,
:class:`bytes`, or :class:`bytearray`.

.. function:: getstate()
Expand Down Expand Up @@ -412,6 +412,31 @@ Alternative Generator
``None``, :class:`int`, :class:`float`, :class:`str`,
:class:`bytes`, or :class:`bytearray`.

.. method:: Random.seed()
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved

Override this method in subclasses to customise the :meth:`random.seed`
behaviour of :class:`Random` instances.

.. method:: Random.getstate()

Override this method in subclasses to customise the :meth:`random.getstate`
behaviour of :class:`Random` instances.

.. method:: Random.setstate()
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved

Override this method in subclasses to customise the :meth:`random.setstate`
behaviour of :class:`Random` instances.

.. method:: Random.getrandbits()
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved

Override this method in subclasses to customise the :meth:`random.getrandbits`
behaviour of :class:`Random` instances.

.. method:: Random.random()

Override this method in subclasses to customise the :meth:`random.random`
behaviour of :class:`Random` instances.

.. class:: SystemRandom([seed])

Class that uses the :func:`os.urandom` function for generating random numbers
Expand Down Expand Up @@ -445,30 +470,30 @@ Examples

Basic examples::

>>> random() # Random float: 0.0 <= x < 1.0
>>> random() # Random float: 0.0 <= x < 1.0
0.37444887175646646

>>> uniform(2.5, 10.0) # Random float: 2.5 <= x <= 10.0
>>> uniform(2.5, 10.0) # Random float: 2.5 <= x <= 10.0
3.1800146073117523

>>> expovariate(1 / 5) # Interval between arrivals averaging 5 seconds
>>> expovariate(1 / 5) # Interval between arrivals averaging 5 seconds
5.148957571865031

>>> randrange(10) # Integer from 0 to 9 inclusive
>>> randrange(10) # Integer from 0 to 9 inclusive
7

>>> randrange(0, 101, 2) # Even integer from 0 to 100 inclusive
>>> randrange(0, 101, 2) # Even integer from 0 to 100 inclusive
26

>>> choice(['win', 'lose', 'draw']) # Single random element from a sequence
>>> choice(['win', 'lose', 'draw']) # Single random element from a sequence
'draw'

>>> deck = 'ace two three four'.split()
>>> shuffle(deck) # Shuffle a list
>>> shuffle(deck) # Shuffle a list
>>> deck
['four', 'two', 'ace', 'three']

>>> sample([10, 20, 30, 40, 50], k=4) # Four samples without replacement
>>> sample([10, 20, 30, 40, 50], k=4) # Four samples without replacement
[40, 10, 50, 30]

Simulations::
Expand Down Expand Up @@ -572,14 +597,14 @@ Simulation of arrival times and service deliveries for a multiserver queue::
including simulation, sampling, shuffling, and cross-validation.

`Economics Simulation
<https://nbviewer.jupyter.org/url/norvig.com/ipython/Economics.ipynb>`_
<https://nbviewer.org/url/norvig.com/ipython/Economics.ipynb>`_
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
a simulation of a marketplace by
`Peter Norvig <https://norvig.com/bio.html>`_ that shows effective
use of many of the tools and distributions provided by this module
(gauss, uniform, sample, betavariate, choice, triangular, and randrange).

`A Concrete Introduction to Probability (using Python)
<https://nbviewer.jupyter.org/url/norvig.com/ipython/Probability.ipynb>`_
<https://nbviewer.org/url/norvig.com/ipython/Probability.ipynb>`_
a tutorial by `Peter Norvig <https://norvig.com/bio.html>`_ covering
the basics of probability theory, how to write simulations, and
how to perform data analysis using Python.
Expand Down
1 change: 0 additions & 1 deletion Doc/tools/.nitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ Doc/library/profile.rst
Doc/library/pyclbr.rst
Doc/library/pydoc.rst
Doc/library/pyexpat.rst
Doc/library/random.rst
Doc/library/readline.rst
Doc/library/resource.rst
Doc/library/select.rst
Expand Down