# [−] [src] Trait rand::distributions::uniform::UniformSampler

    pub trait UniformSampler: Sized {
        type X;
        fn new<B1, B2>(low: B1, high: B2) -> Self
        where
            B1: SampleBorrow<Self::X> + Sized,
            B2: SampleBorrow<Self::X> + Sized;
        fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self
        where
            B1: SampleBorrow<Self::X> + Sized,
            B2: SampleBorrow<Self::X> + Sized;
        fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X;

        fn sample_single<R: Rng + ?Sized, B1, B2>(
            low: B1,
            high: B2,
            rng: &mut R
        ) -> Self::X
        where
            B1: SampleBorrow<Self::X> + Sized,
            B2: SampleBorrow<Self::X> + Sized,
        { ... }
    }

Helper trait handling actual uniform sampling.

See the module documentation on how to implement [`Uniform`] range sampling for a custom type.

Implementation of `sample_single` is optional, and is only useful when the implementation can be faster than `Self::new(low, high).sample(rng)`.

## Associated Types

### `type X`

The type sampled by this implementation.

Loading content...

## Required methods

### `fn new<B1, B2>(low: B1, high: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,`

Construct self, with inclusive lower bound and exclusive upper bound `[low, high)`.

Usually users should not call this directly but instead use `Uniform::new`, which asserts that `low < high` before calling this.

### `fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,`

Construct self, with inclusive bounds `[low, high]`.

Usually users should not call this directly but instead use `Uniform::new_inclusive`, which asserts that `low <= high` before calling this.

### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X`

Sample a value.

Loading content...

## Provided methods

### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low: B1,
high: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,`

Sample a single value uniformly from a range with inclusive lower bound and exclusive upper bound `[low, high)`.

By default this is implemented using `UniformSampler::new(low, high).sample(rng)`. However, for some types more optimal implementations for single usage may be provided via this method (which is the case for integers and floats). Results may not be identical.

Loading content...

## Implementors

### `impl UniformSampler for UniformDuration` [src]

#### `type X = Duration`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Duration` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low: B1,
high: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformFloat<f32>` [src]

#### `type X = f32`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformFloat<f64>` [src]

#### `type X = f64`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<i128>` [src]

#### `type X = i128`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<i16>` [src]

#### `type X = i16`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<i32>` [src]

#### `type X = i32`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<i64>` [src]

#### `type X = i64`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<i8>` [src]

#### `type X = i8`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<isize>` [src]

#### `type X = isize`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<u128>` [src]

#### `type X = u128`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<u16>` [src]

#### `type X = u16`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<u32>` [src]

#### `type X = u32`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<u64>` [src]

#### `type X = u64`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<u8>` [src]

#### `type X = u8`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

### `impl UniformSampler for UniformInt<usize>` [src]

#### `type X = usize`

#### `fn new<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

#### `fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X` [src]

#### `fn sample_single<R: Rng + ?Sized, B1, B2>(
low_b: B1,
high_b: B2,
rng: &mut R
) -> Self::X where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,` [src]

Loading content...

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