From 4b450ca3c6edbc45add181c3805a281a5333e3da Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Thu, 2 May 2024 00:20:54 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#3978=20rand=5Frange()=20=E3=82=92?= =?utf8?q?=E8=AA=BF=E6=95=B4=E3=81=97=E3=81=A6=E5=90=8C=E3=81=98=E5=80=A4?= =?utf8?q?=E3=81=8C=E5=85=A5=E3=81=A3=E3=81=9F=E3=82=89=E4=B9=B1=E6=95=B0?= =?utf8?q?=E3=82=A2=E3=83=AB=E3=82=B4=E3=83=AA=E3=82=BA=E3=83=A0=E3=82=92?= =?utf8?q?=E8=B5=B0=E3=82=89=E3=81=9B=E3=81=9A=E3=81=AB=E5=BC=95=E6=95=B0?= =?utf8?q?=E3=81=AE=E5=80=A4=E3=82=92=E3=81=9D=E3=81=AE=E3=81=BE=E3=81=BE?= =?utf8?q?=E8=BF=94=E3=81=99=E3=82=88=E3=81=86=E9=AB=98=E9=80=9F=E5=8C=96?= =?utf8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/term/z-rand.cpp | 2 +- src/term/z-rand.h | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/term/z-rand.cpp b/src/term/z-rand.cpp index d253e453d..98e4f4bd5 100644 --- a/src/term/z-rand.cpp +++ b/src/term/z-rand.cpp @@ -69,7 +69,7 @@ void Rand_state_init(void) int rand_range(int a, int b) { - if (a > b) { + if (a >= b) { return a; } std::uniform_int_distribution<> d(a, b); diff --git a/src/term/z-rand.h b/src/term/z-rand.h index dda75cccd..6b87d7398 100644 --- a/src/term/z-rand.h +++ b/src/term/z-rand.h @@ -42,10 +42,6 @@ T randnum0(U initial_max) requires(std::is_integral_v || std::is_enum_v) && (std::is_integral_v || std::is_enum_v) { const auto max = static_cast(initial_max); - if (max == 0) { - return static_cast(0); - } - return max > 0 ? static_cast(rand_range(0, max - 1)) : -static_cast(rand_range(0, -max - 1)); } -- 2.11.0