Skip to content

Commit c8b8444

Browse files
committed
Improve documentation for rand::random
This is now linked to in the guide, so I want to make sure it's good. This adds a bit more explanation, and brings usage in line with current good style.
1 parent dd348b3 commit c8b8444

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/libstd/rand/mod.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,24 @@ impl Rng for TaskRng {
226226
}
227227
}
228228

229-
/// Generate a random value using the task-local random number
230-
/// generator.
229+
/// Generates a random value using the task-local random number generator.
231230
///
232-
/// # Example
231+
/// `random()` can generate various types of random things, and so may require
232+
/// type hinting to generate the specific type you want.
233+
///
234+
/// # Examples
233235
///
234236
/// ```rust
235-
/// use std::rand::random;
237+
/// use std::rand;
238+
///
239+
/// let x = rand::random();
240+
/// println!("{}", 2u * x);
241+
///
242+
/// let y = rand::random::<f64>();
243+
/// println!("{}", y);
236244
///
237-
/// if random() {
238-
/// let x = random();
239-
/// println!("{}", 2u * x);
240-
/// } else {
241-
/// println!("{}", random::<f64>());
245+
/// if rand::random() { // generates a boolean
246+
/// println!("Better lucky than good!");
242247
/// }
243248
/// ```
244249
#[inline]

0 commit comments

Comments
 (0)