Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change of Random::DEFAULT -> Random.new is incorrect #2487

Closed
Qqwy opened this issue May 1, 2022 · 3 comments · Fixed by #2488
Closed

Change of Random::DEFAULT -> Random.new is incorrect #2487

Qqwy opened this issue May 1, 2022 · 3 comments · Fixed by #2488

Comments

@Qqwy
Copy link

Qqwy commented May 1, 2022

The merged PR #2225 replaced Random::DEFAULT (which is deprecated in Ruby 3) with Random.new.

@random || Random.new

See #2225 (comment)

However, this is incorrect, and it breaks any test suite which expects reproducible results by seeding the global RNG when a seed argument is used.

The fix is to use Random (the class) instead of Random.new, as this is the new place where the 'global' RNG lives (and indeed Random::DEFAULT refers to Random in Ruby 3).

See the two bullet points under 'Random' in the Ruby 3.0.0 release notes for more info.

@Qqwy
Copy link
Author

Qqwy commented May 1, 2022

It might very well be necessary to add conditional code based on whether we're on Ruby 1, 2 or 3 to work correctly on all Ruby versions.

@connorshea
Copy link
Member

I've merged the fix to master, thanks for pointing this out! And sorry for introducing this problem in the first place 🙈

@Qqwy
Copy link
Author

Qqwy commented May 15, 2022

Thank you for fixing this in a timely manner! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants