1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* random.c (rb_random_int): arguments have to be converted to

integer.  [ruby-core:24679]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-08-02 15:32:04 +00:00
parent 59e5d0f177
commit a194550e5c
3 changed files with 9 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Mon Aug 3 00:32:00 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* random.c (rb_random_int): arguments have to be converted to
integer. [ruby-core:24679]
Sun Aug 2 21:04:37 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Aug 2 21:04:37 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (literal_concat0): tail can be nil. [ruby-dev:38980] * parse.y (literal_concat0): tail can be nil. [ruby-dev:38980]

View file

@ -911,9 +911,10 @@ rb_random_int(VALUE obj, VALUE vmax)
if (NIL_P(v)) { if (NIL_P(v)) {
/* range like object support */ /* range like object support */
if (!(v = range_values(vmax, &beg))) { if (!(v = range_values(vmax, &beg))) {
beg = Qundef; v = vmax;
NUM2LONG(vmax);
} }
v = rb_to_int(v);
beg = rb_to_int(beg);
} }
v = rand_int(&rnd->mt, v); v = rand_int(&rnd->mt, v);
if (NIL_P(v)) v = INT2FIX(0); if (NIL_P(v)) v = INT2FIX(0);

View file

@ -344,6 +344,7 @@ END
1267650600228229401496703205383).each do |w| 1267650600228229401496703205383).each do |w|
assert_equal(w.to_i, r.int(2**100+5..2**100+9)) assert_equal(w.to_i, r.int(2**100+5..2**100+9))
end end
assert_equal(3, r.int(3.1..4), '[ruby-core:24679]')
end end
def test_random_float def test_random_float