added some comments and polished up the code a bit
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
// Generate a random master seed from time and process id.
|
||||
pub fn random_seed() -> u64 {
|
||||
let nanos = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
@@ -9,10 +10,12 @@ pub fn random_seed() -> u64 {
|
||||
mix64(nanos ^ pid.rotate_left(17))
|
||||
}
|
||||
|
||||
// Derive a deterministic seed for a specific random stream.
|
||||
pub fn derive_seed(master_seed: u64, stream_id: u64) -> u64 {
|
||||
mix64(master_seed ^ stream_id.wrapping_mul(0x9E37_79B9_7F4A_7C15))
|
||||
}
|
||||
|
||||
// Mix bits for a 64-bit seed hash.
|
||||
fn mix64(mut x: u64) -> u64 {
|
||||
x = x.wrapping_add(0x9E37_79B9_7F4A_7C15);
|
||||
x = (x ^ (x >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9);
|
||||
|
||||
Reference in New Issue
Block a user