I was reading this section and the last paragraph stated that the example code was not thread-safe. My question is: wouldn’t that help increase its randomness (i.e. if multiple threads were to concurrently execute those lines)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PRNGs are carefully engineered (well, maybe not RANDU) to yield predictable and sufficiently randomly distributed results. They don’t have to be truly random, they just have to satisfy statistical quality tests, yield a large-enough period and be deterministic with the same seed.
If you happen to use the generator from multiple threads simultaneously all those guarantees go down the drain. Most importantly you cannot have a reproducible result (which is extremely important in simulations). Then the state might change or perhaps you get the same number twice in different threads, those things.
You definitely don’t want to go there. Create one PRNG per thread (preferrably with seeds that are linearly independent).