Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16eb827

Browse files
committed
Improve docs for random.seed()
1 parent ab7b0a0 commit 16eb827

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

Doc/library/random.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ Bookkeeping functions:
6363
If *a* is an int, it is used directly.
6464

6565
With version 2 (the default), a :class:`str`, :class:`bytes`, or :class:`bytearray`
66-
object gets converted to an :class:`int` and all of its bits are used. With version 1,
67-
the :func:`hash` of *a* is used instead.
66+
object gets converted to an :class:`int` and all of its bits are used.
67+
68+
With version 1 (provided for reproducing random sequences from older versions
69+
of Python), the algorithm for :class:`str` and :class:`bytes` generates a
70+
narrower range of seeds.
6871

6972
.. versionchanged:: 3.2
7073
Moved to the version 2 scheme which uses all of the bits in a string seed.

Lib/random.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ def seed(self, a=None, version=2):
9696
None or no argument seeds from current time or from an operating
9797
system specific randomness source if available.
9898
99-
For version 2 (the default), all of the bits are used if *a* is a str,
100-
bytes, or bytearray. For version 1, the hash() of *a* is used instead.
101-
10299
If *a* is an int, all bits are used.
103100
101+
For version 2 (the default), all of the bits are used if *a* is a str,
102+
bytes, or bytearray. For version 1 (provided for reproducing random
103+
sequences from older versions of Python), the algorithm for str and
104+
bytes generates a narrower range of seeds.
105+
104106
"""
105107

106108
if a is None:

0 commit comments

Comments
 (0)