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

Random does not behave like the specs #919

Closed
herwinw opened this issue Feb 2, 2023 · 5 comments
Closed

Random does not behave like the specs #919

herwinw opened this issue Feb 2, 2023 · 5 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@herwinw
Copy link
Member

herwinw commented Feb 2, 2023

An observation from #918

MRI's Random has a reproducible output based on the seed. The docs show a few examples, like:

prng1 = Random.new(1234)
prng1.seed       #=> 1234
prng1.rand(100)  #=> 47

I can reproduce this to return 47 on my local machine's MRI. On Natalie, it return 19 for me.

The documentation (emphasis mine)

PRNGs are currently implemented as a modified Mersenne Twister with a period of 2**19937-1.

It does not disclose how it has been altered, so I guess we'll need to distill that from the MRI source. I'm not sure what kind of legal (Copyright etc) implications that may have.

@herwinw herwinw added the bug Something isn't working label Feb 2, 2023
@seven1m
Copy link
Member

seven1m commented Feb 2, 2023

This seems like an implementation detail. I'm surprised that specs are coded to expect certain random output.

I don't currently consider this a bug, but maybe there's some useful "feature" here I'm missing.

@herwinw
Copy link
Member Author

herwinw commented Feb 3, 2023

I think that's more of a discussion for the ruby-spec list. As far as I could find, the Random#bytes spec was the only one that tested specific output, the other specs were all tests to see if the same seed yields the same output.

But given that it's in the spec so all other major implementations have the same output, there are probably people who depend on it. https://xkcd.com/1172/

@seven1m
Copy link
Member

seven1m commented Feb 3, 2023

Fair point, but I'm also OK with being a little bit different here. Natalie can never be a 100% fully compatible Ruby. At the very least, I think we could shelve this until down the road when it is actually a problem for someone.

@herwinw
Copy link
Member Author

herwinw commented Aug 9, 2023

I've finally added an issue in the ruby/spec repository about this issue (ruby/spec#1051). I think we can close this issue for now, and create a new issue if we decide to handle this.

@herwinw herwinw closed this as completed Aug 9, 2023
@eregon
Copy link

eregon commented Aug 10, 2023

FYI: ruby/spec#1051 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants