aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-03-17 18:20:52 +0100
committertomsmeding <tom.smeding@gmail.com>2017-03-17 18:20:52 +0100
commit6b7b41f1ff036d97a9d82f31430c33fb58f45b6a (patch)
tree9c15a19d5be246329187a4f1bb34c00416b1739c
parentd9d996c5caf7d4332f41f06aa44806fe9d33fe96 (diff)
Better srandomdev monkeypatch
-rw-r--r--main.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/main.c b/main.c
index f73afe1..d9fafb4 100644
--- a/main.c
+++ b/main.c
@@ -119,9 +119,14 @@ static bool server_socket_callback(int fd){
}
#ifndef __APPLE__
-#include <sys/time.h>
void srandomdev(void){
- srandom(time(NULL));
+ FILE *f=fopen("/dev/urandom","r");
+ assert(f);
+ unsigned int seed;
+ size_t nread=fread(&seed,1,sizeof(seed),f);
+ assert(nread==sizeof(seed));
+ fclose(f);
+ srandom(seed);
}
#endif