diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-10-10 13:59:55 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-10-23 10:40:06 +1100 |
| commit | 2cd772bdba10ac5b8449595cc218419c33b9bcf4 (patch) | |
| tree | e975938d5c1b89a819ad990ceb5af9df8820890b /src/libstd | |
| parent | ae0905ab67a2dd3def61e266bba9f8f223586af6 (diff) | |
| download | rust-2cd772bdba10ac5b8449595cc218419c33b9bcf4.tar.gz rust-2cd772bdba10ac5b8449595cc218419c33b9bcf4.zip | |
std::rand: add the Sample and IndependentSample traits.
These are a "parameterised" Rand.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/rand/distributions.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libstd/rand/distributions.rs b/src/libstd/rand/distributions.rs index 0902100dca6..845d8bbc952 100644 --- a/src/libstd/rand/distributions.rs +++ b/src/libstd/rand/distributions.rs @@ -23,6 +23,24 @@ use num; use rand::{Rng,Rand}; +/// Things that can be used to create a random instance of `Support`. +pub trait Sample<Support> { + /// Generate a random value of `Support`, using `rng` as the + /// source of randomness. + fn sample<R: Rng>(&mut self, rng: &mut R) -> Support; +} + +/// `Sample`s that do not require keeping track of state, so each +/// sample is (statistically) independent of all others, assuming the +/// `Rng` used has this property. +// XXX maybe having this separate is overkill (the only reason is to +// take &self rather than &mut self)? or maybe this should be the +// trait called `Sample` and the other should be `DependentSample`. +pub trait IndependentSample<Support>: Sample<Support> { + /// Generate a random value. + fn ind_sample<R: Rng>(&self, &mut R) -> Support; +} + mod ziggurat_tables; // inlining should mean there is no performance penalty for this |
