aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_rand.rb11
-rw-r--r--test/test_securerandom.rb14
2 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb
index d4258a7f1c..c24d6cd1ff 100644
--- a/test/ruby/test_rand.rb
+++ b/test/ruby/test_rand.rb
@@ -526,6 +526,17 @@ END
assert_equal(2, gen.limit, bug7935)
end
+ def test_random_ulong_limited_no_rand
+ c = Class.new do
+ undef rand
+ def bytes(n)
+ "\0"*n
+ end
+ end
+ gen = c.new.extend(Random::Formatter)
+ assert_equal(1, [1, 2].sample(random: gen))
+ end
+
def test_default_seed
assert_separately([], <<-End)
seed = Random::DEFAULT::seed
diff --git a/test/test_securerandom.rb b/test/test_securerandom.rb
index 515d05e6b2..cd5cb1dee2 100644
--- a/test/test_securerandom.rb
+++ b/test/test_securerandom.rb
@@ -157,6 +157,20 @@ end
end
end
+ def test_s_random_number_not_default
+ msg = "SecureRandom#random_number should not be affected by srand"
+ seed = srand(0)
+ x = @it.random_number(1000)
+ 10.times do|i|
+ srand(0)
+ return unless @it.random_number(1000) == x
+ end
+ srand(0)
+ assert_not_equal(x, @it.random_number(1000), msg)
+ ensure
+ srand(seed) if seed
+ end
+
def test_uuid
uuid = @it.uuid
assert_equal(36, uuid.size)