From 3e9af0a9107911153c577231f19743cb0f9e20a6 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 13 Jul 2024 19:57:27 +0300 Subject: [PATCH] =?UTF-8?q?fast-path=20for=20n=E2=80=A2rand.Range=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sysfn.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index e8797daa..a705738e 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -365,10 +365,14 @@ B rand_range_c2(B t, B w, B x) { RAND_START; Arr* r; - if (max<1) { - if (max!=0) thrM("(rand).Range: 𝕩 cannot be negative"); - f64* rp; r = m_f64arrp(&rp, am); - PLAINLOOP for (usz i = 0; i < am; i++) rp[i] = wy2u01(wyrand(&seed)); + if (max<=1) { + if (max==0) { + f64* rp; r = m_f64arrp(&rp, am); + PLAINLOOP for (usz i = 0; i < am; i++) rp[i] = wy2u01(wyrand(&seed)); + } else { + if (max!=1) thrM("(rand).Range: 𝕩 cannot be negative"); + r = allZeroes(am); + } } else if (max > (1ULL<<31)) { if (max >= 1LL<<53) thrM("(rand).Range: 𝕩 must be less than 2⋆53"); f64* rp; r = m_f64arrp(&rp, am);