Skip to content

Commit

Permalink
Add UniformSampler::sample_single_inclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Jul 1, 2019
1 parent 266cee2 commit 9f119ff
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/distributions/uniform.rs
Expand Up @@ -259,6 +259,23 @@ pub trait UniformSampler: Sized {
let uniform: Self = UniformSampler::new(low, high);
uniform.sample(rng)
}

/// Sample a single value uniformly from a range with inclusive lower bound
/// and inclusive upper bound `[low, high]`.
///
/// By default this is implemented using
/// `UniformSampler::new_inclusive(low, high).sample(rng)`. However, for
/// some types more optimal implementations for single usage may be provided
/// via this method.
/// Results may not be identical.
fn sample_single_inclusive<R: Rng + ?Sized, B1, B2>(low: B1, high: B2, rng: &mut R)
-> Self::X
where B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized
{
let uniform: Self = UniformSampler::new_inclusive(low, high);
uniform.sample(rng)
}
}

impl<X: SampleUniform> From<::core::ops::Range<X>> for Uniform<X> {
Expand Down

0 comments on commit 9f119ff

Please sign in to comment.