Trait crypto_bigint::RandomMod [−][src]
pub trait RandomMod: Sized {
fn random_mod(rng: impl CryptoRng + RngCore, modulus: &Self) -> Self;
}
This is supported on crate feature
rand
only.Expand description
Modular random number generation support.
Required methods
fn random_mod(rng: impl CryptoRng + RngCore, modulus: &Self) -> Self
fn random_mod(rng: impl CryptoRng + RngCore, modulus: &Self) -> Self
Generate a cryptographically secure random number which is less than
a given modulus
.
This function uses rejection sampling, a method which produces an
unbiased distribution of in-range values provided the underlying
CryptoRng
is unbiased, but runs in variable-time.
The variable-time nature of the algorithm should not pose a security
issue so long as the underlying random number generator is truly a
CryptoRng
, where previous outputs are unrelated to subsequent
outputs and do not reveal information about the RNG’s internal state.