about summary refs log tree commit diff
path: root/src/notd/rand.rs
diff options
context:
space:
mode:
authorvenomade <venomade@venomade.com>2024-02-12 17:15:16 +0000
committervenomade <venomade@venomade.com>2024-02-12 17:15:16 +0000
commit3266619bd9c674d09e3c0699cd0ee39c6b11c24e (patch)
tree530b5c8a662440bd471c155f005d10ec19c89904 /src/notd/rand.rs
Initial Commit
Diffstat (limited to 'src/notd/rand.rs')
-rw-r--r--src/notd/rand.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/notd/rand.rs b/src/notd/rand.rs
new file mode 100644
index 0000000..95c8f0b
--- /dev/null
+++ b/src/notd/rand.rs
@@ -0,0 +1,16 @@
+use std::{
+    collections::hash_map::DefaultHasher,
+    hash::{Hash, Hasher},
+};
+
+pub fn random_from_seed(seed: u64) -> u64 {
+    let mut hasher = DefaultHasher::new();
+    seed.hash(&mut hasher);
+    hasher.finish()
+}
+
+pub fn seed_from_name(name: &str) -> u64 {
+    let mut hasher = DefaultHasher::new();
+    name.hash(&mut hasher);
+    hasher.finish() as u64
+}