| 1 | #[derive(Clone)] |
| 2 | pub enum Row { |
| 3 | DaySeparator(String), |
| 4 | Message(ChatMessage), |
| 5 | } |
| 6 | |
| 7 | #[derive(Clone)] |
| 8 | pub struct ChatMessage { |
| 9 | pub author: String, |
| 10 | pub time: String, |
| 11 | pub markdown: String, |
| 12 | } |
| 13 | |
| 14 | const AUTHORS: [&str; 6] = ["Author A", "Author B", "Author C", "Author D", "Author E", "Author F"]; |
| 15 | const WORDS: [&str; 14] = [ |
| 16 | "alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliet", |
| 17 | "kilo", "lima", "mike", "november", |
| 18 | ]; |
| 19 | |
| 20 | struct Lcg(u64); |
| 21 | |
| 22 | impl Lcg { |
| 23 | fn next(&mut self, bound: u64) -> u64 { |
| 24 | self.0 = self |
| 25 | .0 |
| 26 | .wrapping_mul(6364136223846793005) |
| 27 | .wrapping_add(1442695040888963407); |
| 28 | (self.0 >> 33) % bound |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | fn sentence(random: &mut Lcg, word_count: u64) -> String { |
| 33 | (0..word_count) |
| 34 | .map(|_| WORDS[random.next(WORDS.len() as u64) as usize]) |
| 35 | .collect::<Vec<_>>() |
| 36 | .join(" ") |
| 37 | } |
| 38 | |
| 39 | pub fn synthetic_rows(message_count: usize) -> Vec<Row> { |
| 40 | let mut random = Lcg(42); |
| 41 | let mut rows = Vec::with_capacity(message_count + message_count / 50 + 1); |
| 42 | let mut day = 0; |
| 43 | for message_index in 0..message_count { |
| 44 | if message_index % 50 == 0 { |
| 45 | rows.push(Row::DaySeparator(format!("Day {}", day + 1))); |
| 46 | day += 1; |
| 47 | } |
| 48 | let line_count = 1 + random.next(15); |
| 49 | let mut lines: Vec<String> = Vec::new(); |
| 50 | for line_index in 0..line_count { |
| 51 | let line = match random.next(8) { |
| 52 | 0 => format!("**{}** {}", sentence(&mut random, 2), sentence(&mut random, 8)), |
| 53 | 1 => format!("{} [link {}](https://example.com/{})", sentence(&mut random, 5), message_index, line_index), |
| 54 | _ => { |
| 55 | let word_count = 4 + random.next(24); |
| 56 | sentence(&mut random, word_count) |
| 57 | } |
| 58 | }; |
| 59 | lines.push(line); |
| 60 | } |
| 61 | let mut markdown = lines.join("\n\n"); |
| 62 | if random.next(6) == 0 { |
| 63 | markdown.push_str(&format!( |
| 64 | "\n\n```rust\nfn handler_{message_index}(input: &str) -> usize {{\n input.len() + {message_index}\n}}\n```" |
| 65 | )); |
| 66 | } |
| 67 | rows.push(Row::Message(ChatMessage { |
| 68 | author: AUTHORS[random.next(AUTHORS.len() as u64) as usize].to_string(), |
| 69 | time: format!("{:02}:{:02}", 8 + message_index % 10, (message_index * 7) % 60), |
| 70 | markdown, |
| 71 | })); |
| 72 | } |
| 73 | rows |
| 74 | } |