2009-12-14 23:28:55 +01:00
|
|
|
--- variables.c
|
|
|
|
+++ variables.c 2009-12-04 09:31:06.579929599 +0000
|
|
|
|
@@ -1216,6 +1216,7 @@ static unsigned long rseed = 1;
|
2009-12-08 12:47:31 +01:00
|
|
|
static int last_random_value;
|
2009-12-14 23:28:55 +01:00
|
|
|
static int seeded_subshell = 0;
|
|
|
|
|
|
|
|
+#if !defined(linux)
|
|
|
|
/* A linear congruential random number generator based on the example
|
|
|
|
one in the ANSI C standard. This one isn't very good, but a more
|
|
|
|
complicated one is overkill. */
|
|
|
|
@@ -1264,6 +1265,32 @@ seedrand ()
|
2009-03-03 18:12:53 +01:00
|
|
|
sbrand (tv.tv_sec ^ tv.tv_usec ^ getpid ());
|
2006-12-15 18:03:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+#else
|
2009-12-14 23:28:55 +01:00
|
|
|
+/* Use ISO C Random Number Functions of the glibc */
|
|
|
|
+static int
|
|
|
|
+brand (void)
|
2006-12-15 18:03:59 +01:00
|
|
|
+{
|
2009-12-14 23:28:55 +01:00
|
|
|
+ if (rseed == 0)
|
|
|
|
+ seedrand ();
|
|
|
|
+ return rand() & 32767;
|
2006-12-15 18:03:59 +01:00
|
|
|
+}
|
|
|
|
+
|
2009-12-14 23:28:55 +01:00
|
|
|
+static void
|
|
|
|
+sbrand (unsigned long seed)
|
2006-12-15 18:03:59 +01:00
|
|
|
+{
|
2009-12-14 23:28:55 +01:00
|
|
|
+ rseed = seed;
|
|
|
|
+ srand(seed);
|
2006-12-15 18:03:59 +01:00
|
|
|
+}
|
2009-03-03 18:12:53 +01:00
|
|
|
+
|
|
|
|
+static void
|
2009-12-14 23:28:55 +01:00
|
|
|
+seedrand (void)
|
|
|
|
+{
|
|
|
|
+ struct timeval tv;
|
|
|
|
+ gettimeofday (&tv, NULL);
|
|
|
|
+ srand (tv.tv_sec ^ tv.tv_usec ^ getpid ());
|
|
|
|
+}
|
2006-12-15 18:03:59 +01:00
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
static SHELL_VAR *
|
2009-03-03 18:12:53 +01:00
|
|
|
assign_random (self, value, unused, key)
|
2006-12-15 18:03:59 +01:00
|
|
|
SHELL_VAR *self;
|