Skip to content

Commit 2cd772b

Browse files
committed
std::rand: add the Sample and IndependentSample traits.
These are a "parameterised" Rand.
1 parent ae0905a commit 2cd772b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/libstd/rand/distributions.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@
2323
use num;
2424
use rand::{Rng,Rand};
2525

26+
/// Things that can be used to create a random instance of `Support`.
27+
pub trait Sample<Support> {
28+
/// Generate a random value of `Support`, using `rng` as the
29+
/// source of randomness.
30+
fn sample<R: Rng>(&mut self, rng: &mut R) -> Support;
31+
}
32+
33+
/// `Sample`s that do not require keeping track of state, so each
34+
/// sample is (statistically) independent of all others, assuming the
35+
/// `Rng` used has this property.
36+
// XXX maybe having this separate is overkill (the only reason is to
37+
// take &self rather than &mut self)? or maybe this should be the
38+
// trait called `Sample` and the other should be `DependentSample`.
39+
pub trait IndependentSample<Support>: Sample<Support> {
40+
/// Generate a random value.
41+
fn ind_sample<R: Rng>(&self, &mut R) -> Support;
42+
}
43+
2644
mod ziggurat_tables;
2745

2846
// inlining should mean there is no performance penalty for this

0 commit comments

Comments
 (0)