diff --git a/libexslt/math.c b/libexslt/math.c
index 17138b2..c9f9e5a 100644
--- a/libexslt/math.c
+++ b/libexslt/math.c
@@ -11,6 +11,13 @@
 
 #include <math.h>
 #include <stdlib.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <fcntl.h>
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
 
 #include "exslt.h"
 
@@ -460,6 +467,20 @@ static double
 exsltMathRandom (void) {
     double ret;
     int num;
+    long seed;
+    static int randinit = 0;
+
+    if (!randinit) {
+	int fd = open("/dev/urandom",O_RDONLY);
+
+	seed = time(NULL); /* just in case /dev/urandom is not there */
+	if (fd == -1) {
+		read (fd, &seed, sizeof(seed));
+		close (fd);
+	}
+	srand(seed);
+	randinit = 1;
+    }
 
     num = rand();
     ret = (double)num / (double)RAND_MAX;
-- 
2.27.0

