pub trait Random: Sized {
// Required method
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self;
}
🔬This is a nightly-only experimental API. (
random
)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§
sourcefn random(source: &mut (impl RandomSource + ?Sized)) -> Self
🔬This is a nightly-only experimental API. (random
)
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self
random
)Generates a random value.
Object Safety§
This trait is not object safe.