Trait RandomMod

Source
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§

Source

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.

Implementors§

Source§

impl RandomMod for BoxedUint

Available on crate feature alloc only.
Source§

impl RandomMod for Limb

Source§

impl<const LIMBS: usize> RandomMod for Uint<LIMBS>