]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-142527: Docs: Clarify that random.seed() discards the sign of an integer...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 19 Dec 2025 08:35:34 +0000 (09:35 +0100)
committerGitHub <noreply@github.com>
Fri, 19 Dec 2025 08:35:34 +0000 (08:35 +0000)
gh-142527: Docs: Clarify that random.seed() discards the sign of an integer input (GH-142483)

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).
(cherry picked from commit 610aabfef2f90dc1a274703779615aa5b7fbbb3a)

Co-authored-by: Andrej <andrej.karpathy@gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Doc/library/random.rst

index b1120b3a4d8eb4e8bc88dd99ad29d236fc47523e..dd6b56106afe98196d94f79d9f6e3bd5f251482e 100644 (file)
@@ -78,7 +78,7 @@ Bookkeeping functions
    instead of the system time (see the :func:`os.urandom` function for details
    on availability).
 
-   If *a* is an int, it is used directly.
+   If *a* is an int, its absolute value 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.