Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c34e8604
Kaydet (Commit)
c34e8604
authored
Kas 21, 2016
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
merge
üst
46d8e318
e1329105
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
26 deletions
+31
-26
random.rst
Doc/library/random.rst
+31
-26
No files found.
Doc/library/random.rst
Dosyayı görüntüle @
c34e8604
...
...
@@ -49,8 +49,21 @@ from sources provided by the operating system.
security purposes. For security or cryptographic uses, see the
:mod:`secrets` module.
.. seealso::
Bookkeeping functions:
M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally
equidistributed uniform pseudorandom number generator", ACM Transactions on
Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 1998.
`Complementary-Multiply-with-Carry recipe
<https://code.activestate.com/recipes/576707/>`_ for a compatible alternative
random number generator with a long period and comparatively simple update
operations.
Bookkeeping functions
---------------------
.. function:: seed(a=None, version=2)
...
...
@@ -94,7 +107,8 @@ Bookkeeping functions:
:meth:`randrange` to handle arbitrarily large ranges.
Functions for integers:
Functions for integers
----------------------
.. function:: randrange(stop)
randrange(start, stop[, step])
...
...
@@ -117,7 +131,8 @@ Functions for integers:
``randrange(a, b+1)``.
Functions for sequences:
Functions for sequences
-----------------------
.. function:: choice(seq)
...
...
@@ -188,6 +203,9 @@ Functions for sequences:
If the sample size is larger than the population size, a :exc:`ValueError`
is raised.
Real-valued distributions
-------------------------
The following functions generate specific real-valued distributions. Function
parameters are named after the corresponding variables in the distribution's
equation, as used in common mathematical practice; most of these equations can
...
...
@@ -282,7 +300,8 @@ be found in any statistics text.
parameter.
Alternative Generator:
Alternative Generator
---------------------
.. class:: SystemRandom([seed])
...
...
@@ -294,19 +313,6 @@ Alternative Generator:
:exc:`NotImplementedError` if called.
.. seealso::
M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally
equidistributed uniform pseudorandom number generator", ACM Transactions on
Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 1998.
`Complementary-Multiply-with-Carry recipe
<https://code.activestate.com/recipes/576707/>`_ for a compatible alternative
random number generator with a long period and comparatively simple update
operations.
Notes on Reproducibility
------------------------
...
...
@@ -333,13 +339,13 @@ Basic examples::
>>> random() # Random float: 0.0 <= x < 1.0
0.37444887175646646
>>> uniform(2
, 10) # Random float: 2.0
<= 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
>>> randrange(10) # Integer from 0 to 9
inclusive
7
>>> randrange(0, 101, 2) # Even integer from 0 to 100 inclusive
...
...
@@ -362,17 +368,16 @@ Simulations::
>>> choices(['red', 'black', 'green'], [18, 18, 2], k=6)
['red', 'green', 'black', 'black', 'red', 'black']
# Deal 20 cards without replacement from a deck of 52
#
playing cards and determine the proportion of cards
#
with a ten-value (i.e. a ten,
jack, queen, or king).
# Deal 20 cards without replacement from a deck of 52
playing cards
#
and determine the proportion of cards with a ten-value (i.e. a ten,
# jack, queen, or king).
>>> deck = collections.Counter(tens=16, low_cards=36)
>>> seen = sample(list(deck.elements()), k=20)
>>> print(seen.count('tens') / 20)
0.15
# Estimate the probability of getting 5 or more heads
# from 7 spins of a biased coin that settles on heads
# 60% of the time.
# Estimate the probability of getting 5 or more heads from 7 spins
# of a biased coin that settles on heads 60% of the time.
>>> n = 10000
>>> cw = [0.60, 1.00]
>>> sum(choices('HT', cum_weights=cw, k=7).count('H') >= 5 for i in range(n)) / n
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment