pub trait RandomBits: Sized {
// Required methods
fn try_random_bits(
rng: &mut impl CryptoRngCore,
bit_length: u32,
) -> Result<Self, RandomBitsError>;
fn try_random_bits_with_precision(
rng: &mut impl CryptoRngCore,
bit_length: u32,
bits_precision: u32,
) -> Result<Self, RandomBitsError>;
// Provided methods
fn random_bits(rng: &mut impl CryptoRngCore, bit_length: u32) -> Self { ... }
fn random_bits_with_precision(
rng: &mut impl CryptoRngCore,
bit_length: u32,
bits_precision: u32,
) -> Self { ... }
}
rand_core
only.Expand description
Random bits generation support.
Required Methods§
sourcefn try_random_bits(
rng: &mut impl CryptoRngCore,
bit_length: u32,
) -> Result<Self, RandomBitsError>
fn try_random_bits( rng: &mut impl CryptoRngCore, bit_length: u32, ) -> Result<Self, RandomBitsError>
Generate a cryptographically secure random value in range [0, 2^bit_length)
.
This method is variable time wrt bit_length
.
sourcefn try_random_bits_with_precision(
rng: &mut impl CryptoRngCore,
bit_length: u32,
bits_precision: u32,
) -> Result<Self, RandomBitsError>
fn try_random_bits_with_precision( rng: &mut impl CryptoRngCore, bit_length: u32, bits_precision: u32, ) -> Result<Self, RandomBitsError>
Generate a cryptographically secure 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
.
Provided Methods§
sourcefn random_bits(rng: &mut impl CryptoRngCore, bit_length: u32) -> Self
fn random_bits(rng: &mut impl CryptoRngCore, bit_length: u32) -> Self
Generate a cryptographically secure random value in range [0, 2^bit_length)
.
A wrapper for RandomBits::try_random_bits
that panics on error.
sourcefn random_bits_with_precision(
rng: &mut impl CryptoRngCore,
bit_length: u32,
bits_precision: u32,
) -> Self
fn random_bits_with_precision( rng: &mut impl CryptoRngCore, bit_length: u32, bits_precision: u32, ) -> Self
Generate a cryptographically secure 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.
Object Safety§
Implementors§
impl RandomBits for BoxedUint
alloc
only.