blob: e953f086d5f73f8b95e22d24e929c0540a61ae4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
use std::time::{SystemTime, UNIX_EPOCH};
use rand::{thread_rng, Rng};
pub type MessageID = u64;
pub fn gen_msg_id() -> MessageID {
// Time since UNIX epoch in milliseconds, (48 bits)
let now = SystemTime::now();
let time_millis: u128 = now.duration_since(UNIX_EPOCH).unwrap().as_millis();
// 16 bits of randomness
let rand: u16 = thread_rng().gen();
((time_millis as u64) << 16) | (rand as u64)
}
|