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.

Object Safety§

This trait is not object safe.

Implementors§