Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e132910

Browse files
committed
Misc readability and organization improvements for the random docs
1 parent 0537405 commit e132910

1 file changed

Lines changed: 31 additions & 26 deletions

File tree

Doc/library/random.rst

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,21 @@ from sources provided by the operating system.
4949
security purposes. For security or cryptographic uses, see the
5050
:mod:`secrets` module.
5151

52+
.. seealso::
5253

53-
Bookkeeping functions:
54+
M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally
55+
equidistributed uniform pseudorandom number generator", ACM Transactions on
56+
Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 1998.
57+
58+
59+
`Complementary-Multiply-with-Carry recipe
60+
<https://code.activestate.com/recipes/576707/>`_ for a compatible alternative
61+
random number generator with a long period and comparatively simple update
62+
operations.
63+
64+
65+
Bookkeeping functions
66+
---------------------
5467

5568
.. function:: seed(a=None, version=2)
5669

@@ -94,7 +107,8 @@ Bookkeeping functions:
94107
:meth:`randrange` to handle arbitrarily large ranges.
95108

96109

97-
Functions for integers:
110+
Functions for integers
111+
----------------------
98112

99113
.. function:: randrange(stop)
100114
randrange(start, stop[, step])
@@ -117,7 +131,8 @@ Functions for integers:
117131
``randrange(a, b+1)``.
118132

119133

120-
Functions for sequences:
134+
Functions for sequences
135+
-----------------------
121136

122137
.. function:: choice(seq)
123138

@@ -188,6 +203,9 @@ Functions for sequences:
188203
If the sample size is larger than the population size, a :exc:`ValueError`
189204
is raised.
190205

206+
Real-valued distributions
207+
-------------------------
208+
191209
The following functions generate specific real-valued distributions. Function
192210
parameters are named after the corresponding variables in the distribution's
193211
equation, as used in common mathematical practice; most of these equations can
@@ -282,7 +300,8 @@ be found in any statistics text.
282300
parameter.
283301

284302

285-
Alternative Generator:
303+
Alternative Generator
304+
---------------------
286305

287306
.. class:: SystemRandom([seed])
288307

@@ -294,19 +313,6 @@ Alternative Generator:
294313
:exc:`NotImplementedError` if called.
295314

296315

297-
.. seealso::
298-
299-
M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally
300-
equidistributed uniform pseudorandom number generator", ACM Transactions on
301-
Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 1998.
302-
303-
304-
`Complementary-Multiply-with-Carry recipe
305-
<https://code.activestate.com/recipes/576707/>`_ for a compatible alternative
306-
random number generator with a long period and comparatively simple update
307-
operations.
308-
309-
310316
Notes on Reproducibility
311317
------------------------
312318

@@ -333,13 +339,13 @@ Basic examples::
333339
>>> random() # Random float: 0.0 <= x < 1.0
334340
0.37444887175646646
335341

336-
>>> uniform(2, 10) # Random float: 2.0 <= x < 10.0
342+
>>> uniform(2.5, 10.0) # Random float: 2.5 <= x < 10.0
337343
3.1800146073117523
338344

339-
>>> expovariate(1/5) # Interval between arrivals averaging 5 seconds
345+
>>> expovariate(1 / 5) # Interval between arrivals averaging 5 seconds
340346
5.148957571865031
341347

342-
>>> randrange(10) # Integer from 0 to 9
348+
>>> randrange(10) # Integer from 0 to 9 inclusive
343349
7
344350

345351
>>> randrange(0, 101, 2) # Even integer from 0 to 100 inclusive
@@ -362,17 +368,16 @@ Simulations::
362368
>>> choices(['red', 'black', 'green'], [18, 18, 2], k=6)
363369
['red', 'green', 'black', 'black', 'red', 'black']
364370

365-
# Deal 20 cards without replacement from a deck of 52
366-
# playing cards and determine the proportion of cards
367-
# with a ten-value (i.e. a ten, jack, queen, or king).
371+
# Deal 20 cards without replacement from a deck of 52 playing cards
372+
# and determine the proportion of cards with a ten-value (i.e. a ten,
373+
# jack, queen, or king).
368374
>>> deck = collections.Counter(tens=16, low_cards=36)
369375
>>> seen = sample(list(deck.elements()), k=20)
370376
>>> print(seen.count('tens') / 20)
371377
0.15
372378

373-
# Estimate the probability of getting 5 or more heads
374-
# from 7 spins of a biased coin that settles on heads
375-
# 60% of the time.
379+
# Estimate the probability of getting 5 or more heads from 7 spins
380+
# of a biased coin that settles on heads 60% of the time.
376381
>>> n = 10000
377382
>>> cw = [0.60, 1.00]
378383
>>> sum(choices('HT', cum_weights=cw, k=7).count('H') >= 5 for i in range(n)) / n

0 commit comments

Comments
 (0)