std::random

Trait Random

Source
pub trait Random: Sized {
    // Required method
    fn random(source: &mut (impl RandomSource + ?Sized)) -> Self;
}
🔬This is a nightly-only experimental API. (random #130703)
Expand description

A trait for getting a random value for a type.

Warning: Be careful when manipulating random values! The random method on integers samples them with a uniform distribution, so a value of 1 is just as likely as i32::MAX. By using modulo operations, some of the resulting values can become more likely than others. Use audited crates when in doubt.

Required Methods§

Source

fn random(source: &mut (impl RandomSource + ?Sized)) -> Self

🔬This is a nightly-only experimental API. (random #130703)

Generates a random value.

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§