# [−] [src] Function rand::random

    pub fn random<T>() -> T where
        Standard: Distribution<T>,

Generates a random value using the thread-local random number generator.

This is simply a shortcut for `thread_rng().gen()`. See [`thread_rng`] for documentation of the entropy source and `Standard` for documentation of distributions and type-specific generation.

# Examples

    let x = rand::random::<u8>();
    println!("{}", x);

    let y = rand::random::<f64>();
    println!("{}", y);

    if rand::random() { // generates a boolean
        println!("Better lucky than good!");
    }

If you're calling `random()` in a loop, caching the generator as in the following example can increase performance.

    use rand::Rng;

    let mut v = vec![1, 2, 3];

    for x in v.iter_mut() {
        *x = rand::random()
    }

    // can be made faster by caching thread_rng

    let mut rng = rand::thread_rng();

    for x in v.iter_mut() {
        *x = rng.gen();
    }

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)