in reply to Poor randomness with File::Temp and fork().

I am not sure this to be the case, but here is what I would suspect is going on. If you are calling srand() before forking (or not calling srand), then the children have the same random seed as they start, and thus will get the same sequence of pseudorandom numbers from rand(), which I suspect is being used to generate the random filename in File::Temp. I would also think possibly calling srand inside the forked child might be a way of getting around this issue.

Hope that helps.

  • Comment on Re: Poor randomness with File::Temp and fork().

Replies are listed 'Best First'.
Re^2: Poor randomness with File::Temp and fork().
by Joost (Canon) on Jun 27, 2004 at 17:14 UTC
    If you are calling srand() before forking (or not calling srand) then the children have the same random seed as they start
    Actually, if you don't call srand at all, the children will have different seeds as long as you don't call rand() before the fork() either (since perl 5.004). See perldoc -f srand:
    If srand() is not called explicitly, it is called implicitly at the first use of the "rand" operator.
    In this case, it's probably safest to call srand after the fork() anyway.