Skip to content

Commit

Permalink
Remove deprecated Random::DEFAULT [Feature #17351]
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jan 1, 2022
1 parent 84891bf commit fae0b66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
3 changes: 0 additions & 3 deletions random.c
Expand Up @@ -1816,9 +1816,6 @@ InitVM_Random(void)
rb_define_method(rb_cRandom, "seed", random_get_seed, 0);
#endif

rb_define_const(rb_cRandom, "DEFAULT", rb_cRandom);
rb_deprecate_constant(rb_cRandom, "DEFAULT");

rb_define_singleton_method(rb_cRandom, "srand", rb_f_srand, -1);
rb_define_singleton_method(rb_cRandom, "rand", random_s_rand, -1);
rb_define_singleton_method(rb_cRandom, "bytes", random_s_bytes, 1);
Expand Down
20 changes: 11 additions & 9 deletions spec/ruby/core/random/default_spec.rb
@@ -1,15 +1,17 @@
require_relative '../../spec_helper'

describe "Random::DEFAULT" do
it "returns a random number generator" do
suppress_warning do
Random::DEFAULT.should respond_to(:rand)
ruby_version_is ''...'3.2' do
describe "Random::DEFAULT" do
it "returns a random number generator" do
suppress_warning do
Random::DEFAULT.should respond_to(:rand)
end
end
end

it "changes seed on reboot" do
seed1 = ruby_exe('p Random::DEFAULT.seed', options: '--disable-gems')
seed2 = ruby_exe('p Random::DEFAULT.seed', options: '--disable-gems')
seed1.should != seed2
it "changes seed on reboot" do
seed1 = ruby_exe('p Random::DEFAULT.seed', options: '--disable-gems')
seed2 = ruby_exe('p Random::DEFAULT.seed', options: '--disable-gems')
seed1.should != seed2
end
end
end
6 changes: 3 additions & 3 deletions test/ruby/test_rand.rb
Expand Up @@ -317,7 +317,7 @@ def test_rand_reseed_on_fork
assert_equal(r1, r2, bug5661)

assert_fork_status(1, '[ruby-core:82100] [Bug #13753]') do
Random::DEFAULT.rand(4)
Random.rand(4)
end
rescue NotImplementedError
end
Expand Down Expand Up @@ -395,8 +395,8 @@ def test_default_seed
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
verbose, $VERBOSE = $VERBOSE, nil
seed = Random::DEFAULT::seed
rand1 = Random::DEFAULT::rand
seed = Random.seed
rand1 = Random.rand
$VERBOSE = verbose
rand2 = Random.new(seed).rand
assert_equal(rand1, rand2)
Expand Down

0 comments on commit fae0b66

Please sign in to comment.