Skip to content

Commit ef0d49d

Browse files
committed
auto merge of #16585 : steveklabnik/rust/random_remarks, r=pcwalton
Fixes #15954 and #16354.
2 parents 3570095 + c88feff commit ef0d49d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/doc/guide.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1888,8 +1888,16 @@ fn main() {
18881888

18891889
The first thing we changed was to `use std::rand`, as the docs
18901890
explained. We then added in a `let` expression to create a variable binding
1891-
named `secret_number`, and we printed out its result. Let's try to compile
1892-
this using `cargo build`:
1891+
named `secret_number`, and we printed out its result.
1892+
1893+
Also, you may wonder why we are using `%` on the result of `rand::random()`.
1894+
This operator is called 'modulo', and it returns the remainder of a division.
1895+
By taking the modulo of the result of `rand::random()`, we're limiting the
1896+
values to be between 0 and 99. Then, we add one to the result, making it from 1
1897+
to 100. Using modulo can give you a very, very small bias in the result, but
1898+
for this example, it is not important.
1899+
1900+
Let's try to compile this using `cargo build`:
18931901

18941902
```{notrust,no_run}
18951903
$ cargo build

0 commit comments

Comments
 (0)