pub struct UniformInt<T> { /* private fields */ }
Expand description

Uniform distribution over integral types.

Implementation notes

For simplicity, we use the same generic struct UniformInt<T> for all integer types T. This gives us only one field type, T; to store unsigned values of this size, we take use the fact that these conversions are no-ops.

For a closed range, the number of possible numbers we should generate is range = (high - low + 1). To avoid bias, we must ensure that the size of our sample space, is a multiple of range; other values must be rejected (by replacing with a new random sample). See Fast Random Integer Generation in an Interval for the algorithm used.

As a special case, we use range = 0 to represent the full range of the result type (i.e. for the full inclusive range).

For more information on this bias see the examples/int_bias.rs example.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Generate a random value of T, using rng as the source of randomness.
Generate a random value of T, using rng as the source of randomness.
Generate a random value of T, using rng as the source of randomness.
Generate a random value of T, using rng as the source of randomness.
Generate a random value of T, using rng as the source of randomness.
Generate a random value of T, using rng as the source of randomness.
Generate a random value of T, using rng as the source of randomness.
Generate a random value of T, using rng as the source of randomness.
Generate a random value of T, using rng as the source of randomness.
Generate a random value of T, using rng as the source of randomness.
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more
Create a new instance which samples uniformly from the half-open range [low, high) (excluding high). May panic if low >= high. Read more
Create a new instance which samples uniformly from the closed range [low, high] (inclusive). May panic if low > high. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.