random.c: fix rand() with float range producing out-of-range values

rand_range_float() incorrectly added +1.0 to span for inclusive
ranges, logic copied from integer range handling. For float ranges,
the span should simply be end-begin without adjustment.

Fixes #6720.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-02-21 07:12:52 +09:00
parent 71cb3c2e3a
commit 2031ae9f90
+1 -1
View File
@@ -170,7 +170,7 @@ static mrb_value
rand_range_float(mrb_state *mrb, rand_state *t,
mrb_float begin, mrb_float end,
mrb_bool excl) {
mrb_float span = end - begin + (excl ? 0.0 : 1.0);
mrb_float span = end - begin;
if (span <= 0.0)
return mrb_nil_value();