提交 d8652de9 编写于 作者: B bors

auto merge of #15746 : steveklabnik/rust/docs_random, r=alexcrichton

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.
......@@ -226,19 +226,24 @@ fn fill_bytes(&mut self, bytes: &mut [u8]) {
}
}
/// 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]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册