Skip to content

Commit

Permalink
auto merge of #15746 : steveklabnik/rust/docs_random, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jul 19, 2014
2 parents 8672a23 + c8b8444 commit d8652de
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/libstd/rand/mod.rs
Expand Up @@ -226,19 +226,24 @@ impl Rng for TaskRng {
}
}

/// Generate a random value using the task-local random number
/// generator.
/// Generates a random value using the task-local random number generator.
///
/// # Example
/// `random()` can generate various types of random things, and so may require
/// type hinting to generate the specific type you want.
///
/// # Examples
///
/// ```rust
/// use std::rand::random;
/// use std::rand;
///
/// let x = rand::random();
/// println!("{}", 2u * x);
///
/// let y = rand::random::<f64>();
/// println!("{}", y);
///
/// if random() {
/// let x = random();
/// println!("{}", 2u * x);
/// } else {
/// println!("{}", random::<f64>());
/// if rand::random() { // generates a boolean
/// println!("Better lucky than good!");
/// }
/// ```
#[inline]
Expand Down

0 comments on commit d8652de

Please sign in to comment.