emilio has asked for the wisdom of the Perl Monks concerning the following question:

hello!

Not sure if I have found a bug with the rand() function under mod_perl.

#!/usr/bin/perl use CGI; my $query = new CGI; print $query->header; print "hello<br>"; main(); sub main { my $counter = int(rand(1e12)); print $counter; }

PROBLEM:

if run enough times on an apache webserver running mod_perl, -ie. refreshing 15, 20 times- numbers start repeating. I would assume that some internal variable in the function does not get initialized everytime the code is run?

Replies are listed 'Best First'.
Re: random function bug on mod_perl
by emilio (Initiate) on Apr 02, 2017 at 20:00 UTC
    OK, i am starting to see that there are a few people that have documented the issue on other sites and the root of the problem appears to be in sharing the seed before forking. Perhaps this should be documented better.

      Patches welcome ;)