jeffoodchain opened a new issue, #203: URL: https://github.com/apache/datasketches-rust/issues/203
According to this: https://github.com/apache/datasketches-rust/pull/62#discussion_r2701211297, there's no random support in rust std. I am currently writing `req` but I would need things like this, so I think it might be great to have one in our lib. ```rust use std::cell::Cell; use std::time::SystemTime; use std::time::UNIX_EPOCH; fn seed() -> u64 { let nanos = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap_or_default() .as_nanos() as u64; // xorshift64 degenerates to all zeros if seeded with zero. if nanos == 0 { 0x2545_F491_4F6C_DD1D } else { nanos } } // Returns a pseudo-random bit. pub(crate) fn random_bit() -> bool { thread_local! { static RNG_STATE: Cell<u64> = Cell::new(seed()); } RNG_STATE.with(|state| { let mut x = state.get(); x ^= x << 13; x ^= x >> 7; x ^= x << 17; state.set(x); (x & 1) == 1 }) } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
