2017-04-05 10:47:16 +02:00
|
|
|
commit 047a0fd99e64c554c4edf44cc67ee765b09af017
|
|
|
|
Author: Marcus Meissner <meissner@suse.de>
|
|
|
|
Date: Tue Apr 4 16:27:39 2017 +0200
|
|
|
|
|
|
|
|
initialize the random seed
|
|
|
|
|
2022-08-18 10:45:47 +02:00
|
|
|
Index: libxslt-v1.1.36/libexslt/math.c
|
|
|
|
===================================================================
|
|
|
|
--- libxslt-v1.1.36.orig/libexslt/math.c
|
|
|
|
+++ libxslt-v1.1.36/libexslt/math.c
|
|
|
|
@@ -12,6 +12,14 @@
|
|
|
|
#include <math.h>
|
2017-04-05 10:47:16 +02:00
|
|
|
#include <stdlib.h>
|
2022-08-18 10:45:47 +02:00
|
|
|
|
2017-04-05 10:47:16 +02:00
|
|
|
+#ifdef HAVE_UNISTD_H
|
|
|
|
+#include <unistd.h>
|
|
|
|
+#endif
|
|
|
|
+#include <fcntl.h>
|
|
|
|
+#ifdef HAVE_TIME_H
|
|
|
|
+#include <time.h>
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
#include "exslt.h"
|
|
|
|
|
2022-08-18 10:45:47 +02:00
|
|
|
/**
|
|
|
|
@@ -460,6 +468,20 @@ static double
|
2017-04-05 10:47:16 +02:00
|
|
|
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 */
|
2017-04-07 10:41:51 +02:00
|
|
|
+ if (fd != -1) {
|
2017-04-05 10:47:16 +02:00
|
|
|
+ read (fd, &seed, sizeof(seed));
|
|
|
|
+ close (fd);
|
|
|
|
+ }
|
|
|
|
+ srand(seed);
|
|
|
|
+ randinit = 1;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
num = rand();
|
|
|
|
ret = (double)num / (double)RAND_MAX;
|