# [−] [src] Crate rand

Utilities for random number generation

Rand provides utilities to generate random numbers, to convert them to useful types and distributions, and some randomness-related algorithms.

# Quick Start

To get you started quickly, the easiest and highest-level way to get a random value is to use [`random()`]; alternatively you can use [`thread_rng()`]. The [`Rng`] trait provides a useful API on all RNGs, while the [`distributions`] and [`seq`] modules provide further functionality on top of RNGs.

    use rand::prelude::*;

    if rand::random() { // generates a boolean
        // Try printing a random unicode code point (probably a bad idea)!
        println!("char: {}", rand::random::<char>());
    }

    let mut rng = rand::thread_rng();
    let y: f64 = rng.gen(); // generates a float between 0 and 1

    let mut nums: Vec<i32> = (1..100).collect();
    nums.shuffle(&mut rng);

# The Book

For the user guide and futher documentation, please read The Rust Rand Book.

## Modules

distributions | Generating random samples from probability distributions
prelude | Convenience re-export of common members
rngs | Random number generators and adapters
seq | Sequence-related functionality

## Structs

Error | Error type of random number generators

## Traits

AsByteSliceMut | Trait for casting types to byte slices
CryptoRng | A marker trait used to indicate that an [`RngCore`] or `BlockRngCore` implementation is supposed to be cryptographically secure.
Rng | An automatically-implemented extension trait on [`RngCore`] providing high-level generic methods for sampling values and other convenience methods.
RngCore | The core of a random number generator.
SeedableRng | A random number generator that can be explicitly seeded.

## Functions

random | Generates a random value using the thread-local random number generator.
thread_rng | Retrieve the lazily-initialized thread-local random number generator, seeded by the system. Intended to be used in method chaining style, e.g. `thread_rng().gen::<i32>()`, or cached locally, e.g. `let mut rng = thread_rng();`. Invoked by the `Default` trait, making `ThreadRng::default()` equivalent.

# 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`)