Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by BazB (Priest)
on Jun 27, 2004 at 19:39 UTC ( #370032=note: print w/ replies, xml ) Need Help??


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

Thanks for all the replies.

I must admit, I had overlooked using the template or suffix options that File::Temp offers by default.

I do have calls to rand in other parts of the code (and calls to File::Temp prior to the fork()s), but I was just a little surprised that exactly the same sequences were occurring across so many processes.

dws suggests that calling srand in each child will re-seed the rand function - I'll give that one a shot too, although I did find the warning in the perldoc for 5.6.1 a little concerning:

Do not call srand multiple times in your program unless you know exactly what you're doing and why you're doing it.
...and I wasn't completely sure what I was doing :-)
The docs with 5.8.x aren't quite so stern.

Cheers,

BazB.


If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
That way everyone learns.


Comment on Re: Poor randomness with File::Temp and fork().
Re^2: Poor randomness with File::Temp and fork().
by DrHyde (Prior) on Jun 28, 2004 at 10:04 UTC
    I would suggest having the fork()ed children read some data from /dev/random or /dev/urandom and using that, rather than giving them all their own copy of the pRNG in the same state and so producing the same data. Alternatively, <advert>Net::Random</advert>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (22)
As of 2015-07-06 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (75 votes), past polls