Skip to content

Commit

Permalink
Add ConstantDistribution.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDennis committed Mar 23, 2015
1 parent 547053b commit 6a6be06
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ impl<T> RandDistribution<T> {
}
}

pub struct ConstantDistribution<T>(pub T);

impl<T: Clone> Distribution for ConstantDistribution<T> {
type Output = T;

fn sample<R: Rng>(&self, _: &mut R) -> T {
self.0.clone()
}
}

/// A value with a particular weight for use with `WeightedChoice`.
#[derive(Copy)]
pub struct Weighted<T> {
Expand Down

0 comments on commit 6a6be06

Please sign in to comment.