pub trait RandomBits: Sized {
// Required methods
fn try_random_bits<R: TryRng + ?Sized>(
rng: &mut R,
bit_length: u32,
) -> Result<Self, RandomBitsError<R::Error>>;
fn try_random_bits_with_precision<R: TryRng + ?Sized>(
rng: &mut R,
bit_length: u32,
bits_precision: u32,
) -> Result<Self, RandomBitsError<R::Error>>;
// Provided methods
fn random_bits<R: TryRng + ?Sized>(rng: &mut R, bit_length: u32) -> Self { ... }
fn random_bits_with_precision<R: TryRng + ?Sized>(
rng: &mut R,
bit_length: u32,
bits_precision: u32,
) -> Self { ... }
}Expand description
Random bits generation support.
Required Methods§
Sourcefn try_random_bits<R: TryRng + ?Sized>(
rng: &mut R,
bit_length: u32,
) -> Result<Self, RandomBitsError<R::Error>>
fn try_random_bits<R: TryRng + ?Sized>( rng: &mut R, bit_length: u32, ) -> Result<Self, RandomBitsError<R::Error>>
Generate a random value in range [0, 2^bit_length).
This method is variable time wrt bit_length.
If rng is a CSRNG, the generation is cryptographically secure as well.
§Errors
- Returns
R::Errorin the event the RNG experienced an internal failure.
Sourcefn try_random_bits_with_precision<R: TryRng + ?Sized>(
rng: &mut R,
bit_length: u32,
bits_precision: u32,
) -> Result<Self, RandomBitsError<R::Error>>
fn try_random_bits_with_precision<R: TryRng + ?Sized>( rng: &mut R, bit_length: u32, bits_precision: u32, ) -> Result<Self, RandomBitsError<R::Error>>
Generate a random value in range [0, 2^bit_length),
returning an integer with the closest available size to bits_precision
(if the implementing type supports runtime sizing).
This method is variable time wrt bit_length.
If rng is a CSRNG, the generation is cryptographically secure as well.
§Errors
- Returns
R::Errorin the event the RNG experienced an internal failure.
Provided Methods§
Sourcefn random_bits<R: TryRng + ?Sized>(rng: &mut R, bit_length: u32) -> Self
fn random_bits<R: TryRng + ?Sized>(rng: &mut R, bit_length: u32) -> Self
Generate a random value in range [0, 2^bit_length).
A wrapper for RandomBits::try_random_bits that panics on error.
Sourcefn random_bits_with_precision<R: TryRng + ?Sized>(
rng: &mut R,
bit_length: u32,
bits_precision: u32,
) -> Self
fn random_bits_with_precision<R: TryRng + ?Sized>( rng: &mut R, bit_length: u32, bits_precision: u32, ) -> Self
Generate a random value in range [0, 2^bit_length),
returning an integer with the closest available size to bits_precision
(if the implementing type supports runtime sizing).
A wrapper for RandomBits::try_random_bits_with_precision that panics on error.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".