Random f64 in [0, 1) using RandomState for per-process entropy.
()
| 1082 | |
| 1083 | /// Random f64 in [0, 1) using RandomState for per-process entropy. |
| 1084 | fn rand_f64() -> f64 { |
| 1085 | use std::collections::hash_map::RandomState; |
| 1086 | use std::hash::{BuildHasher, Hasher}; |
| 1087 | let mut hasher = RandomState::new().build_hasher(); |
| 1088 | hasher.write_u64( |
| 1089 | SystemTime::now() |
| 1090 | .duration_since(UNIX_EPOCH) |
| 1091 | .unwrap_or_default() |
| 1092 | .as_nanos() as u64, |
| 1093 | ); |
| 1094 | (hasher.finish() as f64) / (u64::MAX as f64) |
| 1095 | } |
| 1096 | |
| 1097 | #[cfg(test)] |
| 1098 | mod tests { |
no test coverage detected