Skip to content

Commit

Permalink
Improve documentation for rand::random
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
steveklabnik committed Jul 19, 2014
1 parent dd348b3 commit c8b8444
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/libstd/rand/mod.rs
Original file line number Diff line number Diff line change
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

9 comments on commit c8b8444

@bors
Copy link
Contributor

@bors bors commented on c8b8444 Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at steveklabnik@c8b8444

@bors
Copy link
Contributor

@bors bors commented on c8b8444 Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging steveklabnik/rust/docs_random = c8b8444 into auto

@bors
Copy link
Contributor

@bors bors commented on c8b8444 Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steveklabnik/rust/docs_random = c8b8444 merged ok, testing candidate = 66146cde

@bors
Copy link
Contributor

@bors bors commented on c8b8444 Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on c8b8444 Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at steveklabnik@c8b8444

@bors
Copy link
Contributor

@bors bors commented on c8b8444 Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging steveklabnik/rust/docs_random = c8b8444 into auto

@bors
Copy link
Contributor

@bors bors commented on c8b8444 Jul 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steveklabnik/rust/docs_random = c8b8444 merged ok, testing candidate = d8652de

@bors
Copy link
Contributor

@bors bors commented on c8b8444 Jul 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d8652de

Please sign in to comment.