Hi:
I've written the following patch which seems to resolve the issue.
Please consider applying it in your module:
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
Author: Jonathan Yu <frequency@cpan.org>
Bug:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=537952
Bug-CPAN:
https://rt.cpan.org/Ticket/Display.html?id=48080
Forwarded: yes
--- a/Random.pm
+++ b/Random.pm
@@ -73,7 +73,7 @@
### set seeds by default
-salfph(scalar(localtime()));
+salfph(get_seed() || scalar(localtime));
#####################################################################
# RANDOM DEVIATE GENERATORS #
--- a/Random.xs
+++ b/Random.xs
@@ -11,6 +11,28 @@
#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.
+ *
+ * This approach isn't cryptographically secure. Consider using /dev/random
+ * or Math::TrulyRandom to get some real entropy.
+ */
+#define Perl_get_seed (long)(Perl_seed(aTHX) % 1073741824L)
+#else
+/* If we don't support seeds, return 0 so we can fall back to localtime for
+ * default seeding. There's a chance Perl_seed will return 0 and mask this,
+ * but in that case the data should still be "random enough" anyway.
+ */
+#define Perl_get_seed 0L
+#endif /* Perl_seed */
+
static int
not_here(s)
char *s;
@@ -38,6 +60,12 @@
MODULE = Math::Random PACKAGE = Math::Random
+long
+get_seed()
+ CODE:
+ RETVAL = Perl_get_seed;
+ OUTPUT:
+ RETVAL
double
genbet (aa,bb)
On Wed Jul 22 10:36:58 2009, FREQUENCY wrote:
Show quoted text> Hi:
>
> By default, you seed the module using localtime. In the modules I've
> written (currently on CPAN) dealing with random stuff, that's what I've
> done too.
>
> I just learned today that there is a Perl_seed variable we can use,
> which gets the seed of the currently executing thread, which is used
> internally (I guess) for seeding hashes and stuff. Ultimately it should
> prove to be a better default seed.
>
> I'm working on preparing a patch for Debian. There is a bug report on
> this,
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=537952 -- but I
> think the patch could be better, so I'll send the updated one after I'm
> done.
>
> Notably, the patch submitted by Don Armstrong does not ensure that we're
> running on Perl 5.8+, which is when these seeds were introduced.