diff --git a/ChangeLog b/ChangeLog index a2d7281955..1162d05439 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Aug 3 00:32:00 2009 Nobuyoshi Nakada + + * random.c (rb_random_int): arguments have to be converted to + integer. [ruby-core:24679] + Sun Aug 2 21:04:37 2009 Nobuyoshi Nakada * parse.y (literal_concat0): tail can be nil. [ruby-dev:38980] diff --git a/random.c b/random.c index 0855a1bc78..487b84a73e 100644 --- a/random.c +++ b/random.c @@ -911,9 +911,10 @@ rb_random_int(VALUE obj, VALUE vmax) if (NIL_P(v)) { /* range like object support */ if (!(v = range_values(vmax, &beg))) { - beg = Qundef; - NUM2LONG(vmax); + v = vmax; } + v = rb_to_int(v); + beg = rb_to_int(beg); } v = rand_int(&rnd->mt, v); if (NIL_P(v)) v = INT2FIX(0); diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index b932128e23..39444af8ac 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -344,6 +344,7 @@ END 1267650600228229401496703205383).each do |w| assert_equal(w.to_i, r.int(2**100+5..2**100+9)) end + assert_equal(3, r.int(3.1..4), '[ruby-core:24679]') end def test_random_float