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
cfd31f0a
Kaydet (Commit)
cfd31f0a
authored
Şub 13, 2019
tarafından
Raymond Hettinger
Kaydeden (comit)
Miss Islington (bot)
Şub 13, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Be consistent about the use of from-imports in random module (GH-11837)
Minor code clean-up.
üst
73d60023
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
random.py
Lib/random.py
+4
-4
No files found.
Lib/random.py
Dosyayı görüntüle @
cfd31f0a
...
@@ -43,8 +43,8 @@ from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
...
@@ -43,8 +43,8 @@ from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
from
os
import
urandom
as
_urandom
from
os
import
urandom
as
_urandom
from
_collections_abc
import
Set
as
_Set
,
Sequence
as
_Sequence
from
_collections_abc
import
Set
as
_Set
,
Sequence
as
_Sequence
from
hashlib
import
sha512
as
_sha512
from
hashlib
import
sha512
as
_sha512
import
itertools
as
_itertools
from
itertools
import
accumulate
as
_accumulate
import
bisect
as
_bisect
from
bisect
import
bisect
as
_bisect
import
os
as
_os
import
os
as
_os
__all__
=
[
"Random"
,
"seed"
,
"random"
,
"uniform"
,
"randint"
,
"choice"
,
"sample"
,
__all__
=
[
"Random"
,
"seed"
,
"random"
,
"uniform"
,
"randint"
,
"choice"
,
"sample"
,
...
@@ -390,12 +390,12 @@ class Random(_random.Random):
...
@@ -390,12 +390,12 @@ class Random(_random.Random):
_int
=
int
_int
=
int
n
+=
0.0
# convert to float for a small speed improvement
n
+=
0.0
# convert to float for a small speed improvement
return
[
population
[
_int
(
random
()
*
n
)]
for
i
in
range
(
k
)]
return
[
population
[
_int
(
random
()
*
n
)]
for
i
in
range
(
k
)]
cum_weights
=
list
(
_
itertools
.
accumulate
(
weights
))
cum_weights
=
list
(
_accumulate
(
weights
))
elif
weights
is
not
None
:
elif
weights
is
not
None
:
raise
TypeError
(
'Cannot specify both weights and cumulative weights'
)
raise
TypeError
(
'Cannot specify both weights and cumulative weights'
)
if
len
(
cum_weights
)
!=
n
:
if
len
(
cum_weights
)
!=
n
:
raise
ValueError
(
'The number of weights does not match the population'
)
raise
ValueError
(
'The number of weights does not match the population'
)
bisect
=
_bisect
.
bisect
bisect
=
_bisect
total
=
cum_weights
[
-
1
]
+
0.0
# convert to float
total
=
cum_weights
[
-
1
]
+
0.0
# convert to float
hi
=
n
-
1
hi
=
n
-
1
return
[
population
[
bisect
(
cum_weights
,
random
()
*
total
,
0
,
hi
)]
return
[
population
[
bisect
(
cum_weights
,
random
()
*
total
,
0
,
hi
)]
...
...
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