From: Raymond Hettinger Date: Sun, 4 Sep 2016 18:17:28 +0000 (-0700) Subject: Improve docs for random.seed() X-Git-Tag: v3.6.0b1~479^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=16eb827b33cc271eebd521246ebefd4d49470df8;p=thirdparty%2FPython%2Fcpython.git Improve docs for random.seed() --- diff --git a/Doc/library/random.rst b/Doc/library/random.rst index df502a0aff0d..677090a5ff75 100644 --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -63,8 +63,11 @@ Bookkeeping functions: If *a* is an int, it is used directly. With version 2 (the default), a :class:`str`, :class:`bytes`, or :class:`bytearray` - object gets converted to an :class:`int` and all of its bits are used. With version 1, - the :func:`hash` of *a* is used instead. + object gets converted to an :class:`int` and all of its bits are used. + + With version 1 (provided for reproducing random sequences from older versions + of Python), the algorithm for :class:`str` and :class:`bytes` generates a + narrower range of seeds. .. versionchanged:: 3.2 Moved to the version 2 scheme which uses all of the bits in a string seed. diff --git a/Lib/random.py b/Lib/random.py index 06513c824f81..4efbb0a2b92e 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -96,11 +96,13 @@ class Random(_random.Random): None or no argument seeds from current time or from an operating system specific randomness source if available. - For version 2 (the default), all of the bits are used if *a* is a str, - bytes, or bytearray. For version 1, the hash() of *a* is used instead. - If *a* is an int, all bits are used. + For version 2 (the default), all of the bits are used if *a* is a str, + bytes, or bytearray. For version 1 (provided for reproducing random + sequences from older versions of Python), the algorithm for str and + bytes generates a narrower range of seeds. + """ if a is None: