Last active
August 29, 2015 14:17
-
-
Save aturon/d53613d1c0cce1297bf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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