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
ffd2a421
Kaydet (Commit)
ffd2a421
authored
Eyl 10, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 9816: Random.jumpahead(n) didn't work well for small values of n.
üst
d55ffdbe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
2 deletions
+17
-2
random.py
Lib/random.py
+13
-0
test_random.py
Lib/test/test_random.py
+0
-2
NEWS
Misc/NEWS
+4
-0
No files found.
Lib/random.py
Dosyayı görüntüle @
ffd2a421
...
...
@@ -46,6 +46,7 @@ from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
from
math
import
sqrt
as
_sqrt
,
acos
as
_acos
,
cos
as
_cos
,
sin
as
_sin
from
os
import
urandom
as
_urandom
from
binascii
import
hexlify
as
_hexlify
import
hashlib
as
_hashlib
__all__
=
[
"Random"
,
"seed"
,
"random"
,
"uniform"
,
"randint"
,
"choice"
,
"sample"
,
"randrange"
,
"shuffle"
,
"normalvariate"
,
"lognormvariate"
,
...
...
@@ -141,6 +142,18 @@ class Random(_random.Random):
"Random.setstate() of version
%
s"
%
(
version
,
self
.
VERSION
))
def
jumpahead
(
self
,
n
):
"""Change the internal state to one that is likely far away
from the current state. This method will not be in Py3.x,
so it is better to simply reseed.
"""
# The super.jumpahead() method uses shuffling to change state,
# so it needs a large and "interesting" n to work with. Here,
# we use hashing to create a large n for the shuffle.
s
=
repr
(
n
)
+
repr
(
self
.
getstate
())
n
=
int
(
_hashlib
.
new
(
'sha512'
,
s
)
.
hexdigest
(),
16
)
super
(
Random
,
self
)
.
jumpahead
(
n
)
## ---- Methods below this point do not need to be overridden when
## ---- subclassing for the purpose of using a different core generator.
...
...
Lib/test/test_random.py
Dosyayı görüntüle @
ffd2a421
...
...
@@ -55,8 +55,6 @@ class TestBasicOps(unittest.TestCase):
with
test_support
.
check_py3k_warnings
(
quiet
=
True
):
self
.
assertRaises
(
TypeError
,
self
.
gen
.
jumpahead
)
# needs an arg
self
.
assertRaises
(
TypeError
,
self
.
gen
.
jumpahead
,
"ick"
)
# wrong type
self
.
assertRaises
(
TypeError
,
self
.
gen
.
jumpahead
,
2.3
)
# wrong type
self
.
assertRaises
(
TypeError
,
self
.
gen
.
jumpahead
,
2
,
3
)
# too many
def
test_sample
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
ffd2a421
...
...
@@ -43,6 +43,10 @@ Core and Builtins
Library
-------
- Issue #9816: random.Random.jumpahead(n) did not produce a sufficiently
different internal state for small values of n. Fixed by salting the
value.
- Issue #9792: In case of connection failure, socket.create_connection()
would swallow the exception and raise a new one, making it impossible
to fetch the original errno, or to filter timeout errors. Now the
...
...
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