pub trait RandomMod: Sized + Zero {
// Required method
fn random_mod(
rng: &mut (impl RngCore + ?Sized),
modulus: &NonZero<Self>,
) -> Self;
}
Available on crate feature
rand_core
only.Expand description
Modular random number generation support.
Required Methods§
Sourcefn random_mod(
rng: &mut (impl RngCore + ?Sized),
modulus: &NonZero<Self>,
) -> Self
fn random_mod( rng: &mut (impl RngCore + ?Sized), modulus: &NonZero<Self>, ) -> Self
Generate a random number which is less than a given modulus
.
This uses rejection sampling.
As a result, it runs in variable time that depends in part on
modulus
. If the generator rng
is cryptographically secure (for
example, it implements CryptoRng
), then this is guaranteed not to
leak anything about the output value aside from it being less than
modulus
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.