38 lines
774 B
Diff
38 lines
774 B
Diff
--- a/libexslt/math.c 2017-10-30 15:49:55.000000000 +0800
|
|
+++ b/libexslt/math.c 2019-04-18 15:00:54.524000000 +0800
|
|
@@ -23,6 +23,13 @@
|
|
#ifdef HAVE_STDLIB_H
|
|
#include <stdlib.h>
|
|
#endif
|
|
+#ifdef HAVE_UNISTD_H
|
|
+#include <unistd.h>
|
|
+#endif
|
|
+#include <fcntl.h>
|
|
+#ifdef HAVE_TIME_H
|
|
+#include <time.h>
|
|
+#endif
|
|
|
|
#include "exslt.h"
|
|
|
|
@@ -474,6 +481,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;
|