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

Clean up some random number generation related to jitter #2888

Merged

Conversation

bryce-anderson
Copy link
Contributor

@bryce-anderson bryce-anderson commented Apr 2, 2024

Motivation:

Many locations where we have a notion of jitter we require the
jitter to be non-zero. This is because we use
ThreadLocalRandom.nextLong(lower, upper) where with a zero
jitter the bounds are the same and we get an IAE.

Modifications:

  • Add 1 to the upper bound most of our usages of .nextLong(l,u)
    to account for the non-inclusive upper bound.

Motivation:

Many locations where we have a notion of jitter require the
jitter to be non-zero. This is because we use
`ThreadLocalRandom.nextLong(lower, upper)` where with a zero
jitter the bounds are the same and we get an IAE.

Modifications:

- Add 1 to the upper bound most of our usages of `.nextLong(l,u)`
  to account for the non-inclusive upper bound.
@bryce-anderson bryce-anderson changed the title Clean up some random number generation upper bounds related to jitter Clean up some random number generation related to jitter Apr 2, 2024
@bryce-anderson bryce-anderson requested a review from daschl April 3, 2024 15:49
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@bryce-anderson bryce-anderson merged commit 5b04e26 into apple:main Apr 3, 2024
15 checks passed
@bryce-anderson bryce-anderson deleted the bl_anderson/JitterAndRandom branch April 3, 2024 21:30
bryce-anderson added a commit to bryce-anderson/servicetalk that referenced this pull request Apr 11, 2024
Motivation:

In apple#2888 we made it possible to have a zero length jitter
but in a couple places we continue to assert the jitter is
positive despite it being allowed lower.

Modifications:

- Fix a couple examples of this.

Result:

More jitters are allowed to be 0.
bryce-anderson added a commit that referenced this pull request Apr 11, 2024
Motivation:

In #2888 we made it possible to have a zero length jitter
but in a couple places we continue to assert the jitter is
positive despite it being allowed lower.

Modifications:

- Fix a couple examples of this.

Result:

More jitters are allowed to be 0.
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.

3 participants