mirror of
https://github.com/rustdesk/hbb_common.git
synced 2025-07-02 16:07:10 +00:00
time_based_rand
This commit is contained in:
parent
df95f44499
commit
44a7277827
14
src/lib.rs
14
src/lib.rs
@ -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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user