time_based_rand

This commit is contained in:
RustDesk 2025-06-10 12:04:45 +08:00 committed by GitHub
parent df95f44499
commit 44a7277827
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -447,6 +447,20 @@ pub fn version_check_request(typ: String) -> (VersionCheckRequest, String) {
)
}
pub fn time_based_rand() -> u32 {
let nanos = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos();
let mut x = nanos as u64;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
(x % 32768) as u32
}
#[cfg(test)]
mod test {
use super::*;