auto merge of #16585 : steveklabnik/rust/random_remarks, r=pcwalton

Fixes #15954 and #16354.
This commit is contained in:
bors 2014-08-19 13:05:52 +00:00
commit ef0d49d78f
1 changed files with 10 additions and 2 deletions

View File

@ -1888,8 +1888,16 @@ fn main() {
The first thing we changed was to `use std::rand`, as the docs
explained. We then added in a `let` expression to create a variable binding
named `secret_number`, and we printed out its result. Let's try to compile
this using `cargo build`:
named `secret_number`, and we printed out its result.
Also, you may wonder why we are using `%` on the result of `rand::random()`.
This operator is called 'modulo', and it returns the remainder of a division.
By taking the modulo of the result of `rand::random()`, we're limiting the
values to be between 0 and 99. Then, we add one to the result, making it from 1
to 100. Using modulo can give you a very, very small bias in the result, but
for this example, it is not important.
Let's try to compile this using `cargo build`:
```{notrust,no_run}
$ cargo build