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

Correctly use Range from rand #291

Merged
merged 1 commit into from Nov 21, 2017
Merged

Correctly use Range from rand #291

merged 1 commit into from Nov 21, 2017

Conversation

bluejekyll
Copy link
Member

fixes #253

@codecov
Copy link

codecov bot commented Nov 21, 2017

Codecov Report

Merging #291 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #291      +/-   ##
==========================================
+ Coverage   87.24%   87.24%   +<.01%     
==========================================
  Files         114      114              
  Lines       11923    11924       +1     
==========================================
+ Hits        10402    10403       +1     
  Misses       1521     1521
Impacted Files Coverage Δ
proto/src/dns_handle.rs 82.06% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74a9507...ac104bf. Read the comment docs.

@bluejekyll bluejekyll merged commit 43f3390 into master Nov 21, 2017
@@ -212,10 +213,11 @@ where

/// creates random query_id, validates against all active queries
fn next_random_query_id(&self) -> Async<u16> {
let between = Range::new(0, u16::max_value());
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still off by one, right? The upper bound is exclusive.

Copy link
Member Author

Choose a reason for hiding this comment

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

I read this from their docs: All the primitive integer types satisfy this property, and the float types normally satisfy it, but rounding may mean high can occur: https://docs.rs/rand/0.3.18/rand/distributions/range/struct.Range.html

I took that to mean that the top of the Range is the max int, am I reading that incorrectly?

Copy link
Member Author

Choose a reason for hiding this comment

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

The docs confuse me a bit. In one context they discuss primitive integer types satisfying the constraint that it is not inclusive, but then mention but this may be very difficult. And then the next sentence discussing potential rounding up to include the max value. If you know better, I'll change it to +1

Although, going to +1 will require switching up to u32 and then a downcast. Which would be a minor annoyance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I reviewed the src for the Rand. It looks like there is no way for max with u16 to be max. I'll fix this. Thanks for the review.

Copy link
Member Author

Choose a reason for hiding this comment

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

see #292

@bluejekyll bluejekyll deleted the fix_rand_usage branch March 30, 2018 17:15
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.

Inappropriate use of the rand module
2 participants