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§
Provided Methods§
Sourcefn random_from_rng<R: Rng + ?Sized>(rng: &mut R) -> Self
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.
Sourcefn try_random() -> Result<Self, Error>
Available on crate feature getrandom only.
fn try_random() -> Result<Self, Error>
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.
Sourcefn random() -> Self
Available on crate feature getrandom only.
fn random() -> Self
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.