[EXTERNAL] Re: rand is not ISO C compliant in Cygwin

Lavrentiev, Anton (NIH/NLM/NCBI) [C] lavr@ncbi.nlm.nih.gov
Mon Nov 13 16:44:08 GMT 2023


IMHO:

>   2. A different sequence

The word "different" in this context is ambiguous: is it "unrelated" as a generator, or is it "not the same" sequence of the actual numbers?

> I read this as the newlib technique being one way of correctly implementing rand/srand, no?

If the first, then yes; but if the second, then no.

The problem with the first approach is, however, is the inability to adequately randomize your code (e.g. for testing).

You call srand() in the main() thread, and then spawn threads thinking they will inherit the randomization; but in fact, they all start off the same number sequence, regardless.

Anton Lavrentiev
Contractor NIH/NLM/NCBI



More information about the Cygwin mailing list