* array.c (rb_ary_{shuffle_bang,sample}): use Random class object.

* random.c (try_get_rnd): use default_rand for Random as same as
  singleton methods.

* random.c (rb_random_real): check the range of result.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-08-25 22:30:03 +00:00
parent 2034fe610f
commit 8554e16355
5 changed files with 50 additions and 10 deletions

View file

@ -1899,6 +1899,19 @@ class TestArray < Test::Unit::TestCase
end
end
def test_shuffle_random
cc = nil
gen = proc do
10000000
end
class << gen
alias rand call
end
assert_raise(RangeError) {
[*0..2].shuffle(random: gen)
}
end
def test_sample
100.times do
assert([0, 1, 2].include?([2, 1, 0].sample))