Skip to main content

Random

Trait Random 

Source
pub trait Random: Sized {
    // Required method
    fn try_random_from_rng<R: TryRng + ?Sized>(
        rng: &mut R,
    ) -> Result<Self, R::Error>;

    // Provided methods
    fn random_from_rng<R: Rng + ?Sized>(rng: &mut R) -> Self { ... }
    fn try_random() -> Result<Self, Error> { ... }
    fn random() -> Self { ... }
}
Available on crate feature rand_core only.
Expand description

Random number generation support.

Required Methods§

Source

fn try_random_from_rng<R: TryRng + ?Sized>( rng: &mut R, ) -> Result<Self, R::Error>

Generate a random value.

If rng is a CSRNG, the generation is cryptographically secure as well.

§Errors
  • Returns R::Error in the event the RNG experienced an internal failure.

Provided Methods§

Source

fn random_from_rng<R: Rng + ?Sized>(rng: &mut R) -> Self

Generate a random value.

If rng is a CSRNG, the generation is cryptographically secure as well.

Source

fn try_random() -> Result<Self, Error>

Available on crate feature getrandom only.

Randomly generate a value of this type using the system’s ambient cryptographically secure random number generator.

§Errors

Returns getrandom::Error in the event the system’s ambient RNG experiences an internal failure.

Source

fn random() -> Self

Available on crate feature getrandom only.

Randomly generate a value of this type using the system’s ambient cryptographically secure random number generator.

§Panics

This method will panic in the event the system’s ambient RNG experiences an internal failure.

This shouldn’t happen on most modern operating systems.

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 Random for Limb

Source§

impl<MOD, const LIMBS: usize> Random for ConstMontyForm<MOD, LIMBS>
where MOD: ConstMontyParams<LIMBS>,

Source§

impl<T> Random for NonZero<T>
where T: Random + Zero + One + CtAssign,

Source§

impl<T: Random> Random for Wrapping<T>

Source§

impl<const LIMBS: usize> Random for Int<LIMBS>

Source§

impl<const LIMBS: usize> Random for Odd<Uint<LIMBS>>

Source§

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