Skip to content

Commit

Permalink
Add ConstantDistribution.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDennis committed Mar 27, 2015
1 parent 625b7e1 commit b892802
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)]
#[derive(Clone)]
Expand Down

0 comments on commit b892802

Please sign in to comment.