Skip to content

Implement ulong random logic with random bytes#7617

Merged
headius merged 1 commit intojruby:masterfrom
headius:random_random
Feb 6, 2023
Merged

Implement ulong random logic with random bytes#7617
headius merged 1 commit intojruby:masterfrom
headius:random_random

Conversation

@headius
Copy link
Member

@headius headius commented Feb 2, 2023

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.

@headius headius added this to the JRuby 9.4.1.0 milestone Feb 2, 2023
@headius headius marked this pull request as ready for review February 2, 2023 17:09
@headius headius force-pushed the random_random branch 2 times, most recently from 012d6e7 to de106c0 Compare February 2, 2023 20:54
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.
@headius headius merged commit eb4cbc1 into jruby:master Feb 6, 2023
@headius headius deleted the random_random branch February 6, 2023 16:29
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 this pull request may close these issues.

1 participant