mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
random.c: private rand
* random.c (rb_random_ulong_limited): do not call private method rand. [ruby-dev:49892] [Misc #13003] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4509b36666
commit
74ba0cfc62
2 changed files with 12 additions and 1 deletions
2
random.c
2
random.c
|
@ -1018,7 +1018,7 @@ rb_random_ulong_limited(VALUE obj, unsigned long limit)
|
|||
rb_random_t *rnd = try_get_rnd(obj);
|
||||
if (!rnd) {
|
||||
VALUE lim = ulong_to_num_plus_1(limit);
|
||||
VALUE v = rb_to_int(rb_funcallv(obj, id_rand, 1, &lim));
|
||||
VALUE v = rb_to_int(rb_funcallv_public(obj, id_rand, 1, &lim));
|
||||
unsigned long r = NUM2ULONG(v);
|
||||
if (rb_num_negative_p(v)) {
|
||||
rb_raise(rb_eRangeError, "random number too small %ld", r);
|
||||
|
|
|
@ -2337,6 +2337,13 @@ class TestArray < Test::Unit::TestCase
|
|||
end
|
||||
ary = (0...10000).to_a
|
||||
assert_equal(ary.rotate, ary.shuffle(random: gen_to_int))
|
||||
|
||||
assert_raise(NoMethodError) {
|
||||
ary.shuffle(random: Object.new)
|
||||
}
|
||||
assert_raise(NoMethodError) {
|
||||
ary.shuffle!(random: Object.new)
|
||||
}
|
||||
end
|
||||
|
||||
def test_sample
|
||||
|
@ -2437,6 +2444,10 @@ class TestArray < Test::Unit::TestCase
|
|||
end
|
||||
ary = (0...10000).to_a
|
||||
assert_equal(5000, ary.sample(random: gen_to_int))
|
||||
|
||||
assert_raise(NoMethodError) {
|
||||
ary.sample(random: Object.new)
|
||||
}
|
||||
end
|
||||
|
||||
def test_cycle
|
||||
|
|
Loading…
Add table
Reference in a new issue