Skip to content

Commit c73ab02

Browse files
committed
Add ConstantDistribution.
1 parent 6e30259 commit c73ab02

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/distributions/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ impl<T> RandDistribution<T> {
6363
}
6464
}
6565

66+
pub struct ConstantDistribution<T>(pub T);
67+
68+
impl<T: Clone> Distribution for ConstantDistribution<T> {
69+
type Output = T;
70+
71+
fn sample<R: Rng>(&self, _: &mut R) -> T {
72+
let ConstantDistribution(ref value) = *self;
73+
value.clone()
74+
}
75+
}
76+
6677
/// A value with a particular weight for use with `WeightedChoice`.
6778
pub struct Weighted<T> {
6879
/// The numerical weight of this item

0 commit comments

Comments
 (0)