summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/utils.c b/src/utils.c
index bd3ea0e..5647d24 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -48,6 +48,8 @@
#endif
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
@@ -59,6 +61,7 @@
#ifndef WIN32
#include <syslog.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
@@ -161,11 +164,13 @@ int pt_random(void) {
#ifndef TIME_UTC
#define TIME_UTC 1
#endif
- struct timespec ts;
-
- assert(timespec_get(&ts, TIME_UTC));
- srandom(ts.tv_nsec ^ ts.tv_sec);
- return random();
+ static int rng_fd = -1;
+ int rnd_val;
+ if (rng_fd < 0)
+ rng_fd = open("/dev/random", O_RDONLY);
+ assert(rng_fd >= 0);
+ assert( read(rng_fd, &rnd_val, sizeof rnd_val) == sizeof rnd_val );
+ return rnd_val;
#else
srand(time(0));
return rand();