1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::Generator;
pub struct Iter<'a> {
pub(crate) c: &'a Generator,
pub(crate) n: u128,
pub(crate) i: u128,
}
impl<'a> Iterator for Iter<'a> {
type Item = String;
fn next(&mut self) -> Option<Self::Item> {
if self.i == self.n {
None
} else {
self.i += 1;
Some(self.c.generate_exact(self.i - 1))
}
}
}
impl<'a> Iter<'a> {
pub fn random(&self) -> String {
let num = rand::random::<u128>() % self.n;
self.c.generate_exact(num)
}
}