Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by atcroft (Abbot)
on Jun 27, 2004 at 17:00 UTC ( [id://369999]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://369999]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found