]> granicus.if.org Git - python/commitdiff
Issue #29023: Clarify that ints and longs are always deterministic seeds for random.
authorRaymond Hettinger <python@rcn.com>
Sat, 7 Jan 2017 00:13:37 +0000 (16:13 -0800)
committerRaymond Hettinger <python@rcn.com>
Sat, 7 Jan 2017 00:13:37 +0000 (16:13 -0800)
Doc/library/random.rst
Lib/random.py

index 2a3c3af091f677b39280524cfecc579cb9cdd56f..852fe7ca3fbce31f83732b9d1c608c14fddc5460 100644 (file)
@@ -71,17 +71,17 @@ from sources provided by the operating system.
 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.
index 3f96a3770b4e8d517fc1081abb3dc998cd2fd614..11fd35b0de9f5b95203686a444a929626529af3f 100644 (file)
@@ -98,12 +98,14 @@ class Random(_random.Random):
         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: