diff options
| -rw-r--r-- | src/main.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 2c31bd9..c583dc9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,12 +42,27 @@ struct NumberSource { impl Stream for NumberSource { type Item = u32; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { + fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { self.i += 1; Poll::Ready(Some(self.i)) } } +struct RandomSource { + seed: u32, + modulus: u32, + a: u32, + c: u32, +} + +impl Stream for RandomSource { + type Item = u32; + fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { + self.seed = (self.a * self.seed + self.c) % self.modulus; + Poll::Ready(Some(self.seed)) + } +} + fn double<S: Stream<Item = u32>>(input: S) -> impl Stream<Item = u32> { stream! { for await val in input { |
