diff --git a/Cargo.toml b/Cargo.toml index 81a9433..ff8bb2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ debug = false default = [] download-more-ram = ["ureq"] give-up = ["oorandom"] +step-on-lego = ["oorandom"] [[bench]] name = "transmute" diff --git a/src/lib.rs b/src/lib.rs index 8911c7a..7564a98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,22 +52,35 @@ pub fn construct_fake_string(ptr: *mut u8, cap: usize, len: usize) -> String { crate::transmute::<_, String>(actual_buf) } -/// Good for job security. -#[cfg(feature = "give-up")] -pub fn give_up() -> Box { +#[cfg(any(feature = "give-up", feature = "step-on-lego"))] +fn seed() -> u64 { use std::time::SystemTime; + let seed = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap(); + + seed.as_secs() +} + +/// It can be fatal if you step hard enough. +#[cfg(any(feature = "give-up", feature = "step-on-lego"))] +pub fn step_on_lego() -> u32 { + let mut rng = oorandom::Rand64::new(seed() as u128); + + let lego = crate::transmute::(rng.rand_u64() as usize); + + *lego +} + +/// Good for job security. +#[cfg(any(feature = "give-up", feature = "step-on-lego"))] +pub fn give_up() -> Box { let size = std::mem::size_of::(); let mut v = Vec::with_capacity(size); - let mut rng = { - let seed = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap(); - - oorandom::Rand32::new(seed.as_secs()) - }; + let mut rng = oorandom::Rand32::new(seed()); for _ in 0..size { v.push((rng.rand_u32() % 256) as u8);