Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0fff083f
Commit
0fff083f
authored
Dec 08, 2010
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update whatsnew. Salt the random number seed.
parent
9728e309
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
12 deletions
+21
-12
Doc/whatsnew/3.2.rst
Doc/whatsnew/3.2.rst
+12
-6
Lib/random.py
Lib/random.py
+7
-4
Lib/test/test_random.py
Lib/test/test_random.py
+2
-2
No files found.
Doc/whatsnew/3.2.rst
View file @
0fff083f
...
...
@@ -125,7 +125,7 @@ Example of the parser's automatically generated help::
>>> parser.parse_args('-h'.split())
usage:
tmp_argparse_example
.py [-h] -u USER
usage:
manage_cloud
.py [-h] -u USER
{deploy,start,stop} HOSTNAME [HOSTNAME ...]
Manage servers
...
...
@@ -321,10 +321,10 @@ module::
PEP written by Barry Warsaw.
Email
5.1
=====
====
Email
=====
The email package
is extended to be able
to parse and generate email messages
The email package
has been extended
to parse and generate email messages
in bytes format.
* New functions :func:`~email.message_from_bytes` and
...
...
@@ -832,6 +832,7 @@ New, Improved, and Deprecated Modules
(Contributed by Rodolpho Eckhardt and Nick Coghlan, :issue:`10220`.)
.. XXX: notes on new random.seed() version 2
.. XXX: Create a new section for all changes relating to context managers.
.. XXX: Various ConfigParser changes
.. XXX: Mention inspect.getattr_static (Michael Foord)
...
...
@@ -902,7 +903,7 @@ New, Improved, and Deprecated Modules
platbase = "C:\Python32"
prefix = "C:\Python32"
projectbase = "C:\Python32"
py_version = "3.2
b1
"
py_version = "3.2"
py_version_nodot = "32"
py_version_short = "3.2"
srcdir = "C:\Python32"
...
...
@@ -1151,3 +1152,8 @@ require changes to your code:
* The :func:`sys.setfilesystemencoding` function was removed because
it had a flawed design.
* The :func:`random.seed` function and method now performing salting for
string seeds. To access the previous version of *seed* in order to
reproduce Python 3.1 sequences, set the *version* argument to *1*,
``random.seed(s, version=1)``.
Lib/random.py
View file @
0fff083f
...
...
@@ -43,6 +43,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
import
collections
as
_collections
from
hashlib
import
sha512
as
_sha512
__all__
=
[
"Random"
,
"seed"
,
"random"
,
"uniform"
,
"randint"
,
"choice"
,
"sample"
,
"randrange"
,
"shuffle"
,
"normalvariate"
,
"lognormvariate"
,
...
...
@@ -110,9 +111,11 @@ class Random(_random.Random):
import
time
a
=
int
(
time
.
time
()
*
256
)
# use fractional seconds
if
version
==
2
and
isinstance
(
a
,
(
str
,
bytes
,
bytearray
)):
if
version
==
2
:
if
isinstance
(
a
,
(
str
,
bytes
,
bytearray
)):
if
isinstance
(
a
,
str
):
a
=
a
.
encode
(
"utf8"
)
a
+=
_sha512
(
a
).
digest
()
a
=
int
.
from_bytes
(
a
,
'big'
)
super
().
seed
(
a
)
...
...
Lib/test/test_random.py
View file @
0fff083f
...
...
@@ -246,8 +246,8 @@ class MersenneTwister_TestBasicOps(TestBasicOps):
'0x1.1ebb4352e4c4dp-1'
,
'0x1.1a7422abf9c11p-1'
])
self
.
gen
.
seed
(
"the quick brown fox"
,
version
=
2
)
self
.
assertEqual
([
self
.
gen
.
random
().
hex
()
for
i
in
range
(
4
)],
[
'0x1.12
94009b9eda4p-2'
,
'0x1.2ff96171b0010p-1
'
,
'0x1.
459e0989bd8e0p-5'
,
'0x1.8b5f55892ddcb
p-1'
])
[
'0x1.12
39ddfb11b7cp-3'
,
'0x1.b3cbb5c51b120p-4
'
,
'0x1.
8c4f55116b60fp-1'
,
'0x1.63eb525174a27
p-1'
])
def
test_setstate_first_arg
(
self
):
self
.
assertRaises
(
ValueError
,
self
.
gen
.
setstate
,
(
1
,
None
,
None
))
...
...
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