pub trait ContextRandomExt {
// Required methods
fn init_random(&mut self, base_seed: u64);
fn sample<R: RngId + 'static, T>(
&self,
_rng_type: R,
sampler: impl FnOnce(&mut R::RngType) -> T,
) -> T;
fn sample_distr<R: RngId + 'static, T>(
&self,
_rng_type: R,
distribution: impl Distribution<T>,
) -> T
where R::RngType: Rng;
fn sample_range<R: RngId + 'static, S, T>(&self, rng_type: R, range: S) -> T
where R::RngType: Rng,
S: SampleRange<T>,
T: SampleUniform;
fn sample_bool<R: RngId + 'static>(&self, rng_id: R, p: f64) -> bool
where R::RngType: Rng;
fn sample_weighted<R: RngId + 'static, T>(
&self,
rng_id: R,
weights: &[T],
) -> usize
where R::RngType: Rng,
T: Clone + Default + SampleUniform + for<'a> AddAssign<&'a T> + PartialOrd;
}
Required Methods§
fn init_random(&mut self, base_seed: u64)
Sourcefn sample<R: RngId + 'static, T>(
&self,
_rng_type: R,
sampler: impl FnOnce(&mut R::RngType) -> T,
) -> T
fn sample<R: RngId + 'static, T>( &self, _rng_type: R, sampler: impl FnOnce(&mut R::RngType) -> T, ) -> T
Gets a random sample from the random number generator associated with the given
RngId
by applying the specified sampler function. If the Rng has not been used
before, one will be created with the base seed you defined in set_base_random_seed
.
Note that this will panic if set_base_random_seed
was not called yet.
Sourcefn sample_distr<R: RngId + 'static, T>(
&self,
_rng_type: R,
distribution: impl Distribution<T>,
) -> T
fn sample_distr<R: RngId + 'static, T>( &self, _rng_type: R, distribution: impl Distribution<T>, ) -> T
Gets a random sample from the specified distribution using a random number generator
associated with the given RngId
. If the Rng has not been used before, one will be
created with the base seed you defined in set_base_random_seed
.
Note that this will panic if set_base_random_seed
was not called yet.
Sourcefn sample_range<R: RngId + 'static, S, T>(&self, rng_type: R, range: S) -> T
fn sample_range<R: RngId + 'static, S, T>(&self, rng_type: R, range: S) -> T
Gets a random sample within the range provided by range
using the generator associated with the given RngId
.
Note that this will panic if set_base_random_seed
was not called yet.
Sourcefn sample_bool<R: RngId + 'static>(&self, rng_id: R, p: f64) -> bool
fn sample_bool<R: RngId + 'static>(&self, rng_id: R, p: f64) -> bool
Gets a random boolean value which is true with probability p
using the generator associated with the given RngId
.
Note that this will panic if set_base_random_seed
was not called yet.
Sourcefn sample_weighted<R: RngId + 'static, T>(
&self,
rng_id: R,
weights: &[T],
) -> usize
fn sample_weighted<R: RngId + 'static, T>( &self, rng_id: R, weights: &[T], ) -> usize
Draws a random entry out of the list provided in weights
with the given weights using the generator associated with the
given RngId
. Note that this will panic if
set_base_random_seed
was not called yet.
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.