Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a122ad

Browse files
miss-islingtonhugovkAlexWaygood
authored
[3.12]gh-101100: Fix Sphinx warnings in library/random.rst (GH-112981) (#113551)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent0e3cf5b commit5a122ad

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()
@@ -412,6 +410,37 @@ Alternative Generator
412410
``None``,:class:`int`,:class:`float`,:class:`str`,
413411
:class:`bytes`, or:class:`bytearray`.
414412

413+
Subclasses of:class:`!Random` should override the following methods if they
414+
wish to make use of a different basic generator:
415+
416+
..method::Random.seed(a=None, version=2)
417+
418+
Override this method in subclasses to customise the:meth:`~random.seed`
419+
behaviour of:class:`!Random` instances.
420+
421+
..method::Random.getstate()
422+
423+
Override this method in subclasses to customise the:meth:`~random.getstate`
424+
behaviour of:class:`!Random` instances.
425+
426+
..method::Random.setstate(state)
427+
428+
Override this method in subclasses to customise the:meth:`~random.setstate`
429+
behaviour of:class:`!Random` instances.
430+
431+
..method::Random.random()
432+
433+
Override this method in subclasses to customise the:meth:`~random.random`
434+
behaviour of:class:`!Random` instances.
435+
436+
Optionally, a custom generator subclass can also supply the following method:
437+
438+
..method::Random.getrandbits(k)
439+
440+
Override this method in subclasses to customise the
441+
:meth:`~random.getrandbits` behaviour of:class:`!Random` instances.
442+
443+
415444
..class::SystemRandom([seed])
416445

417446
Class that uses the:func:`os.urandom` function for generating random numbers
@@ -445,30 +474,30 @@ Examples
445474

446475
Basic examples::
447476

448-
>>> random()# Random float: 0.0 <= x < 1.0
477+
>>> random() # Random float: 0.0 <= x < 1.0
449478
0.37444887175646646
450479

451-
>>> uniform(2.5, 10.0)# Random float: 2.5 <= x <= 10.0
480+
>>> uniform(2.5, 10.0) # Random float: 2.5 <= x <= 10.0
452481
3.1800146073117523
453482

454-
>>> expovariate(1 / 5)# Interval between arrivals averaging 5 seconds
483+
>>> expovariate(1 / 5) # Interval between arrivals averaging 5 seconds
455484
5.148957571865031
456485

457-
>>> randrange(10)# Integer from 0 to 9 inclusive
486+
>>> randrange(10) # Integer from 0 to 9 inclusive
458487
7
459488

460-
>>> randrange(0, 101, 2)# Even integer from 0 to 100 inclusive
489+
>>> randrange(0, 101, 2) # Even integer from 0 to 100 inclusive
461490
26
462491

463-
>>> choice(['win', 'lose', 'draw'])# Single random element from a sequence
492+
>>> choice(['win', 'lose', 'draw']) # Single random element from a sequence
464493
'draw'
465494

466495
>>> deck = 'ace two three four'.split()
467-
>>> shuffle(deck)# Shuffle a list
496+
>>> shuffle(deck) # Shuffle a list
468497
>>> deck
469498
['four', 'two', 'ace', 'three']
470499

471-
>>> sample([10, 20, 30, 40, 50], k=4)# Four samples without replacement
500+
>>> sample([10, 20, 30, 40, 50], k=4) # Four samples without replacement
472501
[40, 10, 50, 30]
473502

474503
Simulations::
@@ -572,14 +601,14 @@ Simulation of arrival times and service deliveries for a multiserver queue::
572601
including simulation, sampling, shuffling, and cross-validation.
573602

574603
`Economics Simulation
575-
<https://nbviewer.jupyter.org/url/norvig.com/ipython/Economics.ipynb>`_
604+
<https://nbviewer.org/url/norvig.com/ipython/Economics.ipynb>`_
576605
a simulation of a marketplace by
577606
`Peter Norvig<https://norvig.com/bio.html>`_ that shows effective
578607
use of many of the tools and distributions provided by this module
579608
(gauss, uniform, sample, betavariate, choice, triangular, and randrange).
580609

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

‎Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ Doc/library/profile.rst
8282
Doc/library/pyclbr.rst
8383
Doc/library/pydoc.rst
8484
Doc/library/pyexpat.rst
85-
Doc/library/random.rst
8685
Doc/library/readline.rst
8786
Doc/library/resource.rst
8887
Doc/library/select.rst

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp