Project

General

Profile

Actions

Feature #17351

closed

Deprecate Random::DEFAULT

Added by Eregon (Benoit Daloze) almost 4 years ago. Updated about 3 years ago.

Status:
Closed
Target version:
-
[ruby-core:101124]

Description

From https://bugs.ruby-lang.org/issues/17322#note-11

I think we should deprecate the Random::DEFAULT constant, it doesn't make sense anymore and it's longer than using Random class methods (Random.rand) or Kernel instance methods (#rand).
Also, people might expect it to be global.

If users want a Random instance they should just use Random.new, not assume there is a global instance in Random::DEFAULT, which is actually rather misleading now (Random::DEFAULT is no longer an instance of Random).

Also note that JRuby & TruffleRuby use a per-thread instance for Kernel#rand, etc, to avoid contention (otherwise it becomes a huge source of contention when threads run in parallel).
Which means on those implementations using Random::DEFAULT was inefficient (extra synchronization).

So for all these reasons I think it's time to deprecate Random::DEFAULT and then later remove it (in 3.1?).

I don't think there is any use case for Random::DEFAULT, but happy to hear if there is and there is no trivial replacement.


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #17322: Deprecate `Random::DEFAULT` and introduce `Random.default()` method to provide Ractor-supported default random generatorClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0