Jose E. Marchesi wrote:
> Note that my reason for preferring random to random_r in code which must
> not be reentrant is the not documented requirement of memsetting the
> random_data passed to initstate_r to zeroes.  Even if that trick works
> with the current versions of glibc (and the random_r module from gnulib)
> AFAIK nothing guarantees that it will work in the future.

Good point. I have registered a glibc manual bug about it:
http://sourceware.org/bugzilla/show_bug.cgi?id=13595

My understanding is that

  - The memset() is necessary, and is part of BSD culture.

  - The initstate_r() call is only necessary if you want truly different
    numbers at each program run. [1] says:
        "If initstate() has not been called, then random() shall behave
         as though initstate() had been called with seed=1 and size=128."

Bruno

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/initstate.html


Reply via email to