Skip to content

Commit 9a86be2

Browse files
authored
Docs: Clarify that random.seed() discards the sign of an integer input
If *a* is an integer, the sign of *a* is discarded in the C source code. Clarify this behavior to prevent foot guns, where a common use case might naively assume that flipping the sign will produce different sequences (e.g. for a train/test split of a synthetic data generator in machine learning).
1 parent 09d6bf2 commit 9a86be2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Doc/library/random.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ Bookkeeping functions
7878
instead of the system time (see the :func:`os.urandom` function for details
7979
on availability).
8080

81-
If *a* is an int, it is used directly.
81+
If *a* is an int, it is used directly. Note that negative integer seeds are
82+
treated as equivalent to their absolute value, so for example ``seed(-5)`` and
83+
``seed(5)`` will produce identical sequences.
8284

8385
With version 2 (the default), a :class:`str`, :class:`bytes`, or :class:`bytearray`
8486
object gets converted to an :class:`int` and all of its bits are used.

0 commit comments

Comments
 (0)