# Trait rand::Rand [−] [src]

    pub trait Rand: Sized {
        fn rand<R: Rng>(rng: &mut R) -> Self;
    }

A type that can be randomly generated using an `Rng`.

## Built-in Implementations

This crate implements `Rand` for various primitive types. Assuming the provided `Rng` is well-behaved, these implementations generate values with the following ranges and distributions:

- Integers (`i32`, `u32`, `isize`, `usize`, etc.): Uniformly distributed over all values of the type.
- `char`: Uniformly distributed over all Unicode scalar values, i.e. all code points in the range `0...0x10_FFFF`, except for the range `0xD800...0xDFFF` (the surrogate code points). This includes unassigned/reserved code points.
- `bool`: Generates `false` or `true`, each with probability 0.5.
- Floating point types (`f32` and `f64`): Uniformly distributed in the half-open range `[0, 1)`. (The `Open01`, `Closed01`, `Exp1`, and `StandardNormal` wrapper types produce floating point numbers with alternative ranges or distributions.)

The following aggregate types also implement `Rand` as long as their component types implement it:

- Tuples and arrays: Each element of the tuple or array is generated independently, using its own `Rand` implementation.
- `Option<T>`: Returns `None` with probability 0.5; otherwise generates a random `T` and returns `Some(T)`.

## Required Methods

### `fn rand<R: Rng>(rng: &mut R) -> Self`

Generates a random instance of this type using the specified source of randomness.

## Implementations on Foreign Types

### `impl Rand for f64`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> f64`
[src]

Generate a floating point number in the half-open interval `[0,1)`.

See `Closed01` for the closed interval `[0,1]`, and `Open01` for the open interval `(0,1)`.

### `impl Rand for f32`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> f32`
[src]

Generate a floating point number in the half-open interval `[0,1)`.

See `Closed01` for the closed interval `[0,1]`, and `Open01` for the open interval `(0,1)`.

### `impl Rand for isize`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> isize`
[src]

### `impl Rand for i8`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> i8`
[src]

### `impl Rand for i16`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> i16`
[src]

### `impl Rand for i32`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> i32`
[src]

### `impl Rand for i64`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> i64`
[src]

### `impl Rand for usize`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> usize`
[src]

### `impl Rand for u8`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> u8`
[src]

### `impl Rand for u16`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> u16`
[src]

### `impl Rand for u32`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> u32`
[src]

### `impl Rand for u64`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> u64`
[src]

### `impl Rand for char`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> char`
[src]

### `impl Rand for bool`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> bool`
[src]

### `impl Rand for ()`
[src]

#### `fn rand<R: Rng>(_: &mut R)`
[src]

### `impl<A: Rand> Rand for (A,)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A,)`
[src]

### `impl<A: Rand, B: Rand> Rand for (A, B)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B)`
[src]

### `impl<A: Rand, B: Rand, C: Rand> Rand for (A, B, C)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C)`
[src]

### `impl<A: Rand, B: Rand, C: Rand, D: Rand> Rand for (A, B, C, D)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C, D)`
[src]

### `impl<A: Rand, B: Rand, C: Rand, D: Rand, E: Rand> Rand for (A, B, C, D, E)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C, D, E)`
[src]

### `impl<A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand> Rand for (A, B, C, D, E, F)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C, D, E, F)`
[src]

### `impl<A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand> Rand for (A, B, C, D, E, F, G)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C, D, E, F, G)`
[src]

### `impl<A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand> Rand for (A, B, C, D, E, F, G, H)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C, D, E, F, G, H)`
[src]

### `impl<A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand, I: Rand> Rand for (A, B, C, D, E, F, G, H, I)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C, D, E, F, G, H, I)`
[src]

### `impl<A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand, I: Rand, J: Rand> Rand for (A, B, C, D, E, F, G, H, I, J)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C, D, E, F, G, H, I, J)`
[src]

### `impl<A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand, I: Rand, J: Rand, K: Rand> Rand for (A, B, C, D, E, F, G, H, I, J, K)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C, D, E, F, G, H, I, J, K)`
[src]

### `impl<A: Rand, B: Rand, C: Rand, D: Rand, E: Rand, F: Rand, G: Rand, H: Rand, I: Rand, J: Rand, K: Rand, L: Rand> Rand for (A, B, C, D, E, F, G, H, I, J, K, L)`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> (A, B, C, D, E, F, G, H, I, J, K, L)`
[src]

### `impl<T> Rand for [T; 0]`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 0]`
[src]

### `impl<T> Rand for [T; 1] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 1]`
[src]

### `impl<T> Rand for [T; 2] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 2]`
[src]

### `impl<T> Rand for [T; 3] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 3]`
[src]

### `impl<T> Rand for [T; 4] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 4]`
[src]

### `impl<T> Rand for [T; 5] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 5]`
[src]

### `impl<T> Rand for [T; 6] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 6]`
[src]

### `impl<T> Rand for [T; 7] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 7]`
[src]

### `impl<T> Rand for [T; 8] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 8]`
[src]

### `impl<T> Rand for [T; 9] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 9]`
[src]

### `impl<T> Rand for [T; 10] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 10]`
[src]

### `impl<T> Rand for [T; 11] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 11]`
[src]

### `impl<T> Rand for [T; 12] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 12]`
[src]

### `impl<T> Rand for [T; 13] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 13]`
[src]

### `impl<T> Rand for [T; 14] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 14]`
[src]

### `impl<T> Rand for [T; 15] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 15]`
[src]

### `impl<T> Rand for [T; 16] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 16]`
[src]

### `impl<T> Rand for [T; 17] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 17]`
[src]

### `impl<T> Rand for [T; 18] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 18]`
[src]

### `impl<T> Rand for [T; 19] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 19]`
[src]

### `impl<T> Rand for [T; 20] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 20]`
[src]

### `impl<T> Rand for [T; 21] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 21]`
[src]

### `impl<T> Rand for [T; 22] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 22]`
[src]

### `impl<T> Rand for [T; 23] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 23]`
[src]

### `impl<T> Rand for [T; 24] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 24]`
[src]

### `impl<T> Rand for [T; 25] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 25]`
[src]

### `impl<T> Rand for [T; 26] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 26]`
[src]

### `impl<T> Rand for [T; 27] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 27]`
[src]

### `impl<T> Rand for [T; 28] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 28]`
[src]

### `impl<T> Rand for [T; 29] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 29]`
[src]

### `impl<T> Rand for [T; 30] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 30]`
[src]

### `impl<T> Rand for [T; 31] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 31]`
[src]

### `impl<T> Rand for [T; 32] where
T: Rand,`
[src]

#### `fn rand<R: Rng>(_rng: &mut R) -> [T; 32]`
[src]

### `impl<T: Rand> Rand for Option<T>`
[src]

#### `fn rand<R: Rng>(rng: &mut R) -> Option<T>`
[src]

## Implementors

- [src]
  `impl Rand for StandardNormal`
- [src]
  `impl Rand for Exp1`
- [src]
  `impl Rand for Open01<f64>`
- [src]
  `impl Rand for Closed01<f64>`
- [src]
  `impl Rand for Open01<f32>`
- [src]
  `impl Rand for Closed01<f32>`
- [src]
  `impl Rand for ChaChaRng`
- [src]
  `impl Rand for IsaacRng`
- [src]
  `impl Rand for Isaac64Rng`
- [src]
  `impl Rand for XorShiftRng`

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