-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rust-guide::13.3 Generating a secret number #15954
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
Comments
(If you want to mention someone, use |
Done, thanks. |
I pulled this up in the original review: #15729 (comment). As you can see the modulo bias is miniscule (even on 32-bit platforms it is only billionths). |
The introduction of modulo bias is not the main issue. The issue is that I, as a newbie, got confused by the %100 trick, so maybe it needs some more explanation. |
I agree. @anmej If you surround your code with backticks, like |
cc @steveklabnik
This part is somewhat confusing:
let secret_number = (rand::random::<int>() % 100i) + 1i;
My suggestion is: either mention that
rand::random::<int>()
samples the whole range of int and you use modulo to narrow the range. Or use thestd::rand::distributions::Range
function. This way you also don't get modulo bias.The text was updated successfully, but these errors were encountered: