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
c7bab7cb
Kaydet (Commit)
c7bab7cb
authored
Agu 31, 2016
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #27706: Fix regression in random.seed(somestr, version=1)
üst
4786787c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
0 deletions
+30
-0
random.py
Lib/random.py
+7
-0
test_random.py
Lib/test/test_random.py
+18
-0
NEWS
Misc/NEWS
+5
-0
No files found.
Lib/random.py
Dosyayı görüntüle @
c7bab7cb
...
...
@@ -112,6 +112,13 @@ class Random(_random.Random):
import
time
a
=
int
(
time
.
time
()
*
256
)
# use fractional seconds
if
version
==
1
and
isinstance
(
a
,
(
str
,
bytes
)):
x
=
ord
(
a
[
0
])
<<
7
if
a
else
0
for
c
in
a
:
x
=
((
1000003
*
x
)
^
ord
(
c
))
&
0xFFFFFFFFFFFFFFFF
x
^=
len
(
a
)
a
=
-
2
if
x
==
-
1
else
x
if
version
==
2
:
if
isinstance
(
a
,
(
str
,
bytes
,
bytearray
)):
if
isinstance
(
a
,
str
):
...
...
Lib/test/test_random.py
Dosyayı görüntüle @
c7bab7cb
...
...
@@ -326,6 +326,24 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
[
'0x1.1239ddfb11b7cp-3'
,
'0x1.b3cbb5c51b120p-4'
,
'0x1.8c4f55116b60fp-1'
,
'0x1.63eb525174a27p-1'
])
def
test_bug_27706
(
self
):
# Verify that version 1 seeds are unaffected by hash randomization
self
.
gen
.
seed
(
'nofar'
,
version
=
1
)
# hash('nofar') == 5990528763808513177
self
.
assertEqual
([
self
.
gen
.
random
()
.
hex
()
for
i
in
range
(
4
)],
[
'0x1.8645314505ad7p-1'
,
'0x1.afb1f82e40a40p-5'
,
'0x1.2a59d2285e971p-1'
,
'0x1.56977142a7880p-6'
])
self
.
gen
.
seed
(
'rachel'
,
version
=
1
)
# hash('rachel') == -9091735575445484789
self
.
assertEqual
([
self
.
gen
.
random
()
.
hex
()
for
i
in
range
(
4
)],
[
'0x1.0b294cc856fcdp-1'
,
'0x1.2ad22d79e77b8p-3'
,
'0x1.3052b9c072678p-2'
,
'0x1.578f332106574p-3'
])
self
.
gen
.
seed
(
''
,
version
=
1
)
# hash('') == 0
self
.
assertEqual
([
self
.
gen
.
random
()
.
hex
()
for
i
in
range
(
4
)],
[
'0x1.b0580f98a7dbep-1'
,
'0x1.84129978f9c1ap-1'
,
'0x1.aeaa51052e978p-2'
,
'0x1.092178fb945a6p-2'
])
def
test_setstate_first_arg
(
self
):
self
.
assertRaises
(
ValueError
,
self
.
gen
.
setstate
,
(
1
,
None
,
None
))
...
...
Misc/NEWS
Dosyayı görüntüle @
c7bab7cb
...
...
@@ -55,6 +55,11 @@ Library
-
Issue
#
19884
:
Avoid
spurious
output
on
OS
X
with
Gnu
Readline
.
-
Issue
#
27706
:
Restore
deterministic
behavior
of
random
.
Random
().
seed
()
for
string
seeds
using
seeding
version
1.
Allows
sequences
of
calls
to
random
()
to
exactly
match
those
obtained
in
Python
2.
Patch
by
Nofar
Schnider
.
-
Issue
#
10513
:
Fix
a
regression
in
Connection
.
commit
().
Statements
should
not
be
reset
after
a
commit
.
...
...
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