From bcba8f6b466d3ed3962c8a5722c313db739bec43 Mon Sep 17 00:00:00 2001 From: "d.grigonis" Date: Wed, 19 Mar 2025 01:08:24 +0200 Subject: [PATCH 1/2] impl --- Lib/random.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/random.py b/Lib/random.py index 4d9a047b027974..d6f5337d40f6ba 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -336,8 +336,11 @@ def randrange(self, start, stop=None, step=_ONE): def randint(self, a, b): """Return random integer in range [a, b], including both end points. """ - - return self.randrange(a, b+1) + a = _index(a) + b = _index(b) + if b < a: + raise ValueError(f"empty range in randint({a}, {b})") + return a + self._randbelow(b - a + 1) ## -------------------- sequence methods ------------------- From 01244f4196ad75469975a897a745bd0c583d0b79 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 20:37:10 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-03-19-20-37-07.gh-issue-131435.y8KMae.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-03-19-20-37-07.gh-issue-131435.y8KMae.rst diff --git a/Misc/NEWS.d/next/Library/2025-03-19-20-37-07.gh-issue-131435.y8KMae.rst b/Misc/NEWS.d/next/Library/2025-03-19-20-37-07.gh-issue-131435.y8KMae.rst new file mode 100644 index 00000000000000..1a9810a8fed7d5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-03-19-20-37-07.gh-issue-131435.y8KMae.rst @@ -0,0 +1 @@ +10-20% performance improvement of :func:`random.randint`.