Skip to content

Commit 096a5dd

Browse files
committed
UniformSampler: add doc on usage of sample_single
1 parent f78781a commit 096a5dd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/distributions/uniform.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ pub trait UniformSampler: Sized {
245245
/// more optimal implementations for single usage may be provided via this
246246
/// method (which is the case for integers and floats).
247247
/// Results may not be identical.
248+
///
249+
/// Note that to use this method in a generic context, the type needs to be
250+
/// retrieved via `SampleUniform::Sampler` as follows:
251+
/// ```
252+
/// use rand::{thread_rng, distributions::uniform::{SampleUniform, UniformSampler}};
253+
/// # #[allow(unused)]
254+
/// fn sample_from_range<T: SampleUniform>(lb: T, ub: T) -> T {
255+
/// let mut rng = thread_rng();
256+
/// <T as SampleUniform>::Sampler::sample_single(lb, ub, &mut rng)
257+
/// }
258+
/// ```
248259
fn sample_single<R: Rng + ?Sized, B1, B2>(low: B1, high: B2, rng: &mut R)
249260
-> Self::X
250261
where B1: SampleBorrow<Self::X> + Sized,

0 commit comments

Comments
 (0)