summaryrefslogtreecommitdiff
path: root/common/src/msg_id.rs
diff options
context:
space:
mode:
authorAria <me@aria.rip>2023-10-13 01:33:38 +0100
committerAria <me@aria.rip>2023-10-13 01:33:38 +0100
commit1b6c1b425f78f4ec3eb275f21a792776e50cbf93 (patch)
tree9adb3c9fc11ee379078b60243f1705e991f7bf5d /common/src/msg_id.rs
parent186087b2010f7f2b9631a28b80527d99b751b882 (diff)
start using async
Diffstat (limited to 'common/src/msg_id.rs')
-rw-r--r--common/src/msg_id.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/common/src/msg_id.rs b/common/src/msg_id.rs
new file mode 100644
index 0000000..e953f08
--- /dev/null
+++ b/common/src/msg_id.rs
@@ -0,0 +1,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)
+}