Re: Sinister variable caching problem with rand()
Cosimo Streppone <[email protected]>
| Newsgroups | gmane.comp.apache.mod-perl |
|---|---|
| Message-ID | <[email protected]> |
On Sat, 15 May 2010 22:03:50 +0200, Anthony Esposito <[email protected]> wrote: > In one of my programs I started to receive database errors for not > having a unique id. I generate unique ids for each of the mysql lines > that I add to the database. I realized that the perl variable $idNum was > keeping the same random string for multiple executions. I've been there too. Same problem, with mod perl 2.04. This is what I have in my startup.pl: # Every mp process needs a different random seed, or they will # generate the exact same random number sequence every time, # resulting in tokens collision my $srv = Apache2::ServerUtil->server; $srv->push_handlers(PerlChildInitHandler => sub { srand(time ^ $$) } ); -- Cosimo