summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2023-07-21 22:06:31 -0700
committerRose Hogenson <rosehogenson@posteo.net>2023-07-21 22:06:31 -0700
commit8b05a73daf89613ff52e9f10ae1529a90da7ae0d (patch)
tree473b7d886db3e955b78786a42cdd023941a6618e /src
parentb5caf80b8f18fcafca3ff697f219070825620695 (diff)
downloadstallman-shooter-8b05a73daf89613ff52e9f10ae1529a90da7ae0d.tar.zst
Remove reading from /dev/urandom.
For greater portability, we will only use the system time for seeding the random generator. It's not like it matters anyway.
Diffstat (limited to 'src')
-rw-r--r--src/rand.rs25
1 files changed, 2 insertions, 23 deletions
diff --git a/src/rand.rs b/src/rand.rs
index 404e115..aa322ba 100644
--- a/src/rand.rs
+++ b/src/rand.rs
@@ -5,34 +5,13 @@ use std::time::SystemTime;
static STATE: Mutex<u64> = Mutex::new(0);
-fn seed_urandom() -> Option<()> {
- let mut f = File::open("/dev/urandom").ok()?;
- let mut bytes = [0; 8];
- f.read_exact(&mut bytes).ok()?;
-
- *STATE.lock().unwrap() = u64::from_ne_bytes(bytes);
- return Some(());
-}
-
-fn seed_time() -> Option<()> {
+pub fn seed() -> Option<()> {
let n = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?;
-
*STATE.lock().unwrap() = n.as_nanos() as u64;
- return Some(());
-}
-pub fn seed() -> Option<()> {
- match seed_urandom() {
- Some(()) => return Some(()),
- None => (),
- }
- match seed_time() {
- Some(()) => return Some(()),
- None => (),
- }
- return None;
+ return Some(());
}
fn mix(s: &mut u64) {