Description: Update seeding algorithm
 By default, this algorithm uses localtime to seed the random number
 generator, which provides poor randomness when Perl is executed many
 times sequentially. This patch replaces that with Don Armstrong's
 proposed solution, Perl_seed. See BTS#537952 for details.
Origin: vendor
Bug-Debian: http://bugs.debian.org/537952
Bug: https://rt.cpan.org/Ticket/Display.html?id=48080
Forwarded: yes
Author: Jonathan Yu <frequency@cpan.org>
Reviewed-by: gregor herrmann <gregoa@debian.org>
Last-Update: 2011-05-09

--- a/Random.pm
+++ b/Random.pm
@@ -73,7 +73,12 @@
 
 
 ### set seeds by default
-salfph(scalar(localtime()));
+if ($] > 5.008001) {
+  set_default_seed();
+}
+else {
+  salfph(scalar localtime);
+}
 
 #####################################################################
 #		      RANDOM DEVIATE GENERATORS                     #
--- a/Random.xs
+++ b/Random.xs
@@ -11,6 +11,23 @@
 #include "randlib.h"
 #include "helper.h"
 
+#define PERL_VERSION_ATLEAST(a,b,c)				\
+  (PERL_REVISION > (a)						\
+   || (PERL_REVISION == (a)					\
+       && (PERL_VERSION > (b)					\
+           || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c)))))
+
+#if PERL_VERSION_ATLEAST (5,8,1)
+/* For whatever reason, the random seeds need to be in 1..2^30; the below will
+ * be uniformly distributed assuming the seed value is uniformly distributed.
+ */
+#define default_seed_mechanism \
+  setall((long)(Perl_seed(aTHX) % 1073741824L), \
+         (long)(Perl_seed(aTHX) % 1073741824L));
+#else /* Perl < 5.8.1 */
+#define default_seed_mechanism not_here("Perl_seed");
+#endif
+
 static int
 not_here(s)
 char *s;
@@ -38,6 +55,10 @@
 
 MODULE = Math::Random		PACKAGE = Math::Random		
 
+void
+set_default_seed()
+        CODE:
+        default_seed_mechanism;
 
 double
 genbet (aa,bb)
