8000 gh-101100: Fix Sphinx warnings in library/random.rst (GH-112981) · miss-islington/cpython@1e011e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e011e9

Browse files
hugovkAlexWaygood
authored andcommitted
pythongh-101100: Fix Sphinx warnings in library/random.rst (pythonGH-112981)
(cherry picked from commit 8e5d70f) Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 656eb16 commit 1e011e9

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

Doc/library/random.rst

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ instance of the :class:`random.Random` class. You can instantiate your own
3434
instances of :class:`Random` to get generators that don't share state.
3535

3636
Class :class:`Random` can also be subclassed if you want to use a different
37-
basic generator of your own devising: in that case, override the :meth:`~Random.random`,
38-
:meth:`~Random.seed`, :meth:`~Random.getstate`, and :meth:`~Random.setstate` methods.
39-
Optionally, a new generator can supply a :meth:`~Random.getrandbits` method --- this
40-
allows :meth:`randrange` to produce selections over an arbitrarily large range.
37+
basic generator of your own devising: see the documentation on that class for
38+
more details.
4139

4240
The :mod:`random` module also provides the :class:`SystemRandom` class which
4341
uses the system function :func:`os.urandom` to generate random numbers
@@ -88,7 +86,7 @@ Bookkeeping functions
8886

8987
.. versionchanged:: 3.11
9088
The *seed* must be one of the following types:
91-
*NoneType*, :class:`int`, :class:`float`, :class:`str`,
89+
``None``, :class:`int`, :class:`float`, :class:`str`,
9290
:class:`bytes`, or :class:`bytearray`.
9391

9492
.. function:: getstate()
@@ -388,6 +386,37 @@ Alternative Generator
388386
``None``, :class:`int`, :class:`float`, :class:`str`,
389387
:class:`bytes`, or :class:`bytearray`.
390388

389+
Subclasses of :class:`!Random` should override the following methods if they
390+
wish to make use of a different basic generator:
391+
392+
.. method:: Random.seed(a=None, version=2)
393+
394+
Override this method in subclasses to customise the :meth:`~random.seed`
395+
behaviour of :class:`!Random` instances.
396+
397+
.. method:: Random.getstate()
398+
399+
Override this method in subclasses to customise the :meth:`~random.getstate`
400+
behaviour of :class:`!Random` instances.
401+
402+
.. method:: Random.setstate(state)
403+
404+
Override this method in subclasses to customise the :meth:`~random.setstate`
405+
behaviour of :class:`!Random` instances.
406+
407+
.. method:: Random.random()
408+
409+
Override this method in subclasses to customise the :meth:`~random.random`
410+
behaviour of :class:`!Random` instances.
411+
412+
Optionally, a custom generator subclass can also supply the following method:
413+
414+
.. method:: Random.getrandbits(k)
415+
416+
Override this method in subclasses to customise the
417+
:meth:`~random.getrandbits` behaviour of :class:`!Random` instances.
418+
419+
391420
.. class:: SystemRandom([seed])
392421

393422
Class that uses the :func:`os.urandom` function for generating random numbers
@@ -421,30 +450,30 @@ Examples
421450

422451
Basic examples::
423452

424-
>>> random() # Random float: 0.0 <= x < 1.0
453+
>>> random() # Random float: 0.0 <= x < 1.0
425454
0.37444887175646646
426455

427-
>>> uniform(2.5, 10.0) # Random float: 2.5 <= x <= 10.0
456+
>>> uniform(2.5, 10.0) # Random float: 2.5 <= x <= 10.0
428457
3.1800146073117523
429458

430-
>>> expovariate(1 / 5) # Interval between arrivals averaging 5 seconds
459+
>>> expovariate(1 / 5) # Interval between arrivals averaging 5 seconds
431460
5.148957571865031
432461

433-
>>> randrange(10) # Integer from 0 to 9 inclusive
462+
>>> randrange(10) # Integer from 0 to 9 inclusive
434463
7
435464

436-
>>> randrange(0, 101, 2) # Even integer from 0 to 100 inclusive
465+
>>> randrange(0, 101, 2) # Even integer from 0 to 100 inclusive
437466
26
438467

439-
>>> choice(['win', 'lose', 'draw']) # Single random element from a sequence
468+
>>> choice(['win', 'lose', 'draw']) # Single random element from a sequence
440469
'draw'
441470

442471
>>> deck = 'ace two three four'.split()
443-
>>> shuffle(deck) # Shuffle a list
472+
>>> shuffle(deck) # Shuffle a list
444473
>>> deck
445474
['four', 'two', 'ace', 'three']
446475

447-
>>> sample([10, 20, 30, 40, 50], k=4) # Four samples without replacement
476+
>>> sample([10, 20, 30, 40, 50], k=4) # Four samples without replacement
448477
[40, 10, 50, 30]
449478

450479
Simulations::
@@ -551,14 +580,14 @@ Simulation of arrival times and service deliveries for a multiserver queue::
551580
including simulation, sampling, shuffling, and cross-validation.
552581

553582
`Economics Simulation
554-
<https://nbviewer.jupyter.org/url/norvig.com/ipython/Economics.ipynb>`_
583+
<https://nbviewer.org/url/norvig.com/ipython/Economics.ipynb>`_
555584
a simulation of a marketplace by
556585
`Peter Norvig <https://norvig.com/bio.html>`_ that shows effective
557586
use of many of the tools and distributions provided by this module
558587
(gauss, uniform, sample, betavariate, choice, triangular, and randrange).
559588

560589
`A Concrete Introduction to Probability (using Python)
561-
<https://nbviewer.jupyter.org/url/norvig.com/ipython/Probability.ipynb>`_
590+
<https://nbviewer.org/url/norvig.com/ipython/Probability.ipynb>`_
562591
a tutorial by `Peter Norvig <https://norvig.com/bio.html>`_ covering
563592
the basics of probability theory, how to write simulations, and
564593
how to perform data analysis using Python.

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ Doc/library/profile.rst
7474
Doc/library/pyclbr.rst
7575
Doc/library/pydoc.rst
7676
Doc/library/pyexpat.rst
77-
Doc/library/random.rst
7877
Doc/library/readline.rst
7978
Doc/library/resource.rst
8079
Doc/library/select.rst

0 commit comments

Comments
 (0)
0