Implement ulong random logic with random bytes#7617
Merged
headius merged 1 commit intojruby:masterfrom Feb 6, 2023
Merged
Conversation
012d6e7 to
de106c0
Compare
CRuby first attempts to call `bytes` on the given random object in order to allow random number implementations to override only that one method in order to change the random number source. We were skipping this logic and going straight back to our internal PRNG logic. This had two effects: * SecureRandom and similar classes would not always be the source for random numbers they appear to generate, since this callback to `bytes` was not happening for long-ranged random numbers. * The test_ulong_limited_no_rand test from CRuby's test_rand.rb failed 50% of the time because we continued to generate actual random numbers (1..2) rather than using the non-random overridden `bytes` method.
de106c0 to
64c7e89
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CRuby first attempts to call
byteson the given random object in order to allow random number implementations to override only that one method in order to change the random number source. We were skipping this logic and going straight back to our internal PRNG logic.This had two effects:
byteswas not happening for long-ranged random numbers.bytesmethod.