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 6e30259 commit c73ab02
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ 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 {
let ConstantDistribution(ref value) = *self;
value.clone()
}
}

/// A value with a particular weight for use with `WeightedChoice`.
pub struct Weighted<T> {
/// The numerical weight of this item
Expand Down

0 comments on commit c73ab02

Please sign in to comment.