mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user