The man page for rand_r()
states:
The value pointed to by the seedp argument of rand_r() provides only a very small amount of state, so this function will be a weak pseudo-random generator.
Could someone explain what this sentence means? How is it that the seed value "provides only a very small amount of state", and how does that weaken the generator?
Before I start using the GNU extension drand48_r()
as a better alternative, I want to be sure I am making an informed choice. Perhaps for some use cases rand_r()
is sufficient, otherwise there would be no sense in it being available.
EDIT in response to comments:
I wish to better undestand the functions and the way they are explained, preferrably without reference to a particular use case that could constrain the explanation. There are plenty of use cases discussed on the net, but general knowledge about the functions is either lacking or difficult to understand. SO has in the past been great with Q&A introductions, hence my question.
If it helps, I have done a test to compare rand()
and rand_r()
, producing two random RGB images, where the pixels were generated with:
pxsPtr[i] = (uint8_t) rand() % 255; // rand() version
pxsPtr[i] = (uint8_t) rand_r(&randRseed) % 255; // rand_r() version
I'm surprised by their similarity and now even more eager to obtain answers to my questions.