pub trait RandomMod: Sized + Zero {
// Required method
fn try_random_mod_vartime<R: TryRng + ?Sized>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Result<Self, R::Error>;
// Provided methods
fn random_mod_vartime<R: Rng + ?Sized>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Self { ... }
fn random_mod<R: Rng + ?Sized>(rng: &mut R, modulus: &NonZero<Self>) -> Self { ... }
fn try_random_mod<R: TryRng + ?Sized>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Result<Self, R::Error> { ... }
}rand_core only.Expand description
Modular random number generation support.
Required Methods§
Sourcefn try_random_mod_vartime<R: TryRng + ?Sized>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Result<Self, R::Error>
fn try_random_mod_vartime<R: TryRng + ?Sized>( rng: &mut R, modulus: &NonZero<Self>, ) -> Result<Self, R::Error>
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.
§Errors
- Returns
R::Errorin the event the RNG experienced an internal failure.
Provided Methods§
Sourcefn random_mod_vartime<R: Rng + ?Sized>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Self
fn random_mod_vartime<R: Rng + ?Sized>( rng: &mut R, 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.
Sourcefn random_mod<R: Rng + ?Sized>(rng: &mut R, modulus: &NonZero<Self>) -> Self
👎Deprecated since 0.7.0: please use random_mod_vartime instead
fn random_mod<R: Rng + ?Sized>(rng: &mut R, modulus: &NonZero<Self>) -> Self
random_mod_vartime insteadGenerate 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.
Sourcefn try_random_mod<R: TryRng + ?Sized>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Result<Self, R::Error>
👎Deprecated since 0.7.0: please use try_random_mod_vartime instead
fn try_random_mod<R: TryRng + ?Sized>( rng: &mut R, modulus: &NonZero<Self>, ) -> Result<Self, R::Error>
try_random_mod_vartime insteadGenerate 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.
§Errors
- Returns
R::Errorin the event the RNG experienced an internal failure.
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.