diff --git a/src/main.rs b/src/main.rs index ff21ed5..e03beb6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,11 +11,25 @@ impl Rng { .duration_since(SystemTime::UNIX_EPOCH) .unwrap() .subsec_nanos() as u64; - Self { state: seed ^ 0x9e3779b97f4a7c15 } + // Allegedly + // It's XOR'd with the seed (`subsec_nanos()`) as a **mixing step** — + // the golden ratio has a property where it distributes bits very evenly across + // the range, so even a low-entropy seed gets spread across all 64 bits + // before the first LCG iteration runs + Self { + state: seed ^ 0x9e3779b97f4a7c15, + } } fn next_u64(&mut self) -> u64 { - self.state = self.state.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407); + // Allegedly + // Knuth MMIX LCG constants: + // multiplier chosen for spectral quality (for uniform distribution) + // addend must be odd for full 2^64 period + self.state = self + .state + .wrapping_mul(6364136223846793005) + .wrapping_add(1442695040888963407); self.state } @@ -109,7 +123,7 @@ fn main() { println!("Complete {ROUNDS} questions to finish a round.\n"); let stdin = io::stdin(); - let mut stdin = stdin.lock(); + let mut stdin = stdin.lock(); // why lock? let mut rng = Rng::new(); let mut stats: Vec = Vec::with_capacity(ROUNDS); @@ -156,12 +170,16 @@ fn main() { } fn print_summary(stats: &[QuestionStats]) { + // voodoo let total_time: Duration = stats.iter().map(|s| s.time_taken).sum(); let total_mistakes: u32 = stats.iter().map(|s| s.mistakes).sum(); let perfect = stats.iter().filter(|s| s.mistakes == 0).count(); println!("=== Round Complete ===\n"); - println!("{:<5} {:<12} {:<8} {:>10} {:>8}", "#", "Question", "Answer", "Time (s)", "Mistakes"); + println!( + "{:<5} {:<12} {:<8} {:>10} {:>8}", + "#", "Question", "Answer", "Time (s)", "Mistakes" + ); println!("{}", "-".repeat(50)); for (i, s) in stats.iter().enumerate() { @@ -179,7 +197,11 @@ fn print_summary(stats: &[QuestionStats]) { println!("{}", "-".repeat(50)); println!( "{:<5} {:<12} {:<8} {:>10.2} {:>8}", - "Tot", "", "", total_time.as_secs_f64(), total_mistakes + "Tot", + "", + "", + total_time.as_secs_f64(), + total_mistakes ); - println!("\nPerfect (no mistakes): {}/{}", perfect, stats.len()); + println!("\nScore: {}/{}", perfect, stats.len()); }