use std::time::{SystemTime, UNIX_EPOCH};
fn linear_congruential_generator(seed: &mut u64) -> u64 {
const A: u64 = 1664525;
const C: u64 = 1013904223;
const M: u64 = 1 << 32;
*seed = (*seed).wrapping_mul(A).wrapping_add(C) % M;
*seed
}
pub fn gen_rand_vec<T: Random>(n: usize) -> Vec<T> {
let start = SystemTime::now();
let duration = start
.duration_since(UNIX_EPOCH)
.expect("Oh shit broo, time went backwards!");
let mut seed = duration.as_secs();
(0..n).map(|_| T::random(&mut seed)).collect()
}
pub trait Random {
fn random(seed: &mut u64) -> Self;
}
impl Random for f64 {
fn random(seed: &mut u64) -> Self {
linear_congruential_generator(seed) as f64 / (u64::MAX as f64)
}
}
impl Random for i64 {
fn random(seed: &mut u64) -> Self {
const MAX: i64 = 50_000;
(linear_congruential_generator(seed) % (MAX as u64)) as i64
}
}
impl Random for i32 {
fn random(seed: &mut u64) -> Self {
const MAX: i64 = 5_000;
(linear_congruential_generator(seed) % (MAX as u64)) as i32
}
}
impl Random for u8 {
fn random(seed: &mut u64) -> Self {
const MAX: u8 = 10;
(linear_congruential_generator(seed) % (MAX as u64)) as u8
}
}