From 15f29b8fa06a5b5d25a0d4783d7940fdf73b00d2 Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 25 Feb 2023 19:57:50 +0100 Subject: [PATCH] * patch by Rika: Perform 32-bit random if the bound fits into 32 bits at runtime, resolves #40171 --- rtl/inc/system.inc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rtl/inc/system.inc b/rtl/inc/system.inc index 3eafe4f4fa..ee5a1764bf 100644 --- a/rtl/inc/system.inc +++ b/rtl/inc/system.inc @@ -739,6 +739,14 @@ var q, bd, ad, bc, ac: qword; carry: qword; begin + if (l>=Low(int32)) and (l<=High(int32)) then + begin + { random(longint(l)), inlined. This makes random(NativeType) on 64-bit platforms match 32-bit when possible. } + if (l < 0) then + inc(l); + exit(longint(int64(system.random(high(int32)))*l shr 32)); + end; + if (l < 0) then begin inc(l);