Skip to content

Instantly share code, notes, and snippets.

@aturon
Last active August 29, 2015 14:17
Show Gist options
  • Save aturon/d53613d1c0cce1297bf1 to your computer and use it in GitHub Desktop.
Save aturon/d53613d1c0cce1297bf1 to your computer and use it in GitHub Desktop.
trait Rand<Distribution> {
type Stream: RandStream<T>;
fn rand(dist: Distribution) -> Stream;
}
trait RandStream<T> {
fn next<R: Rng>(&self, rng: &mut R) -> T;
}
impl Rand<Range<u32, u32>> for u32 {
type Stream = SomePreprocessedDistribution;
fn rand(dist: Range<u32, u32>) -> Stream {
SomePreprocessedDistribution::preprocess(dist)
}
}
impl RandStream<u32> for SomePreprocessedDistribution {
fn next<R: Rng>(&self, rng: &mut R) -> u32 {
// do the sampling
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment