pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/c8d03187ff85326ab8b24af06f8a4e391365f42a

merge · python/cpython@c8d0318 · GitHub
Skip to content

Commit c8d0318

Browse files
committed
merge
2 parents 8209cec + 71c62e1 commit c8d0318

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

Doc/library/random.rst

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,25 +364,29 @@ Basic examples::
364364

365365
Simulations::
366366

367-
# Six roulette wheel spins (weighted sampling with replacement)
367+
>>> # Six roulette wheel spins (weighted sampling with replacement)
368368
>>> choices(['red', 'black', 'green'], [18, 18, 2], k=6)
369369
['red', 'green', 'black', 'black', 'red', 'black']
370370

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).
371+
>>> # Deal 20 cards without replacement from a deck of 52 playing cards
372+
>>> # and determine the proportion of cards with a ten-value
373+
>>> # (a ten, jack, queen, or king).
374374
>>> deck = collections.Counter(tens=16, low_cards=36)
375375
>>> seen = sample(list(deck.elements()), k=20)
376-
>>> print(seen.count('tens') / 20)
376+
>>> seen.count('tens') / 20
377377
0.15
378378

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.
381-
>>> n = 10000
382-
>>> cw = [0.60, 1.00]
383-
>>> sum(choices('HT', cum_weights=cw, k=7).count('H') >= 5 for i in range(n)) / n
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.
381+
>>> trial = lambda: choices('HT', cum_weights=(0.60, 1.00), k=7).count('H') >= 5
382+
>>> sum(trial() for i in range(10000)) / 10000
384383
0.4169
385384

385+
>>> # Probability of the median of 5 samples being in middle two quartiles
386+
>>> trial = lambda : 2500 <= sorted(choices(range(10000), k=5))[2] < 7500
387+
>>> sum(trial() for i in range(10000)) / 10000
388+
0.7958
389+
386390
Example of `statistical bootstrapping
387391
<https://en.wikipedia.org/wiki/Bootstrapping_(statistics)>`_ using resampling
388392
with replacement to estimate a confidence interval for the mean of a sample of

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy