Skip to content

Commit b892802

Browse files
committed
Add ConstantDistribution.
1 parent 625b7e1 commit b892802

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/distributions/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ impl<T> RandDistribution<T> {
6262
}
6363
}
6464

65+
pub struct ConstantDistribution<T>(pub T);
66+
67+
impl<T: Clone> Distribution for ConstantDistribution<T> {
68+
type Output = T;
69+
70+
fn sample<R: Rng>(&self, _: &mut R) -> T {
71+
self.0.clone()
72+
}
73+
}
74+
6575
/// A value with a particular weight for use with `WeightedChoice`.
6676
#[derive(Copy)]
6777
#[derive(Clone)]

0 commit comments

Comments
 (0)