[Python-checkins] cpython (2.7): Issue #29023: Clarify that ints and longs are always deterministic seeds for
raymond.hettinger
python-checkins at python.org
Fri Jan 6 19:13:41 EST 2017
https://hg.python.org/cpython/rev/7d6ebd206cd6
changeset: 106024:7d6ebd206cd6
branch: 2.7
parent: 106009:e908e90fb147
user: Raymond Hettinger <python at rcn.com>
date: Fri Jan 06 16:13:37 2017 -0800
summary:
Issue #29023: Clarify that ints and longs are always deterministic seeds for random.
files:
Doc/library/random.rst | 18 +++++++++---------
Lib/random.py | 6 ++++--
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -71,17 +71,17 @@
Bookkeeping functions:
-.. function:: seed([x])
+.. function:: seed(a=None)
- Initialize the basic random number generator. Optional argument *x* can be any
- :term:`hashable` object. If *x* is omitted or ``None``, current system time is used;
- current system time is also used to initialize the generator when the module is
- first imported. If randomness sources are provided by the operating system,
- they are used instead of the system time (see the :func:`os.urandom` function
- for details on availability).
+ Initialize internal state of the random number generator.
- If a :term:`hashable` object is given, deterministic results are only assured
- when :envvar:`PYTHONHASHSEED` is disabled.
+ ``None`` or no argument seeds from current time or from an operating
+ system specific randomness source if available (see the :func:`os.urandom`
+ function for details on availability).
+
+ If *a* is not ``None`` or an :class:`int` or a :class:`long`, then
+ ``hash(a)`` is used instead. Note that the hash values for some types
+ are nondeterministic when :envvar:`PYTHONHASHSEED` is enabled.
.. versionchanged:: 2.4
formerly, operating system resources were not used.
diff --git a/Lib/random.py b/Lib/random.py
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -98,12 +98,14 @@
self.gauss_next = None
def seed(self, a=None):
- """Initialize internal state from hashable object.
+ """Initialize internal state of the random number generator.
None or no argument seeds from current time or from an operating
system specific randomness source if available.
- If a is not None or an int or long, hash(a) is used instead.
+ If a is not None or is an int or long, hash(a) is used instead.
+ Hash values for some types are nondeterministic when the
+ PYTHONHASHSEED environment variable is enabled.
"""
if a is None:
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list