From 2f80e46dd94666afe8afdbc929c1711103221122 Mon Sep 17 00:00:00 2001 From: Kirti Aggarwal <47375858+kirtiagwl1595@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:07:49 +0530 Subject: [PATCH 1/2] gh-116245: Document getentropy() use in os.urandom() --- Doc/library/os.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 7f4b698eac38cd8..5332f59d4162120 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -6466,9 +6466,14 @@ Random numbers random bytes in non-blocking mode (using the :data:`GRND_NONBLOCK` flag) or to poll until the system urandom entropy pool is initialized. - On a Unix-like system, random bytes are read from the ``/dev/urandom`` - device. If the ``/dev/urandom`` device is not available or not readable, the - :exc:`NotImplementedError` exception is raised. + On other Unix-like systems, the C ``getrandom()`` or ``getentropy()`` + function is used if it is available, for example ``getentropy()`` on OpenBSD + and on macOS 10.12 and newer. + + On any Unix-like system, if none of these functions can be used, random + bytes are read from the ``/dev/urandom`` device. If the ``/dev/urandom`` + device is not available or not readable, the :exc:`NotImplementedError` + exception is raised. On Windows, it will use ``BCryptGenRandom()``. From 98a08aa324c0676036c53e08b2ebf9219b6d3796 Mon Sep 17 00:00:00 2001 From: Kirti Aggarwal <47375858+kirtiagwl1595@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:26:45 +0530 Subject: [PATCH 2/2] Apply review suggestion: state getrandom()/getentropy() order Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/library/os.rst | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 5332f59d4162120..9cf4a4efe5c0ee9 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -6466,14 +6466,12 @@ Random numbers random bytes in non-blocking mode (using the :data:`GRND_NONBLOCK` flag) or to poll until the system urandom entropy pool is initialized. - On other Unix-like systems, the C ``getrandom()`` or ``getentropy()`` - function is used if it is available, for example ``getentropy()`` on OpenBSD - and on macOS 10.12 and newer. + On other Unix-like systems, the C ``getrandom()`` function is used if it is + available, otherwise the C ``getentropy()`` function. - On any Unix-like system, if none of these functions can be used, random - bytes are read from the ``/dev/urandom`` device. If the ``/dev/urandom`` - device is not available or not readable, the :exc:`NotImplementedError` - exception is raised. + If none of these functions can be used, random bytes are read from the + ``/dev/urandom`` device. If the ``/dev/urandom`` device is not available or + not readable, the :exc:`NotImplementedError` exception is raised. On Windows, it will use ``BCryptGenRandom()``.