curl-library
Re[2]: Calls to srand() in Curl_FormBoundary()
Date: Sun, 14 Jun 2009 00:41:37 +0400
Hello,
PM> Daniel Stenberg wrote:
>> Wouldn't it be good enough to move the srand() call to the
>> curl_global_init() function?
Yes, this is much better. Note that the user must re-seed the rand()
generator in each forked child with some unique value, otherwise the
sequences will be the same in all forked children. I assume that
curl_global_init() is called before the main app starts forking child
processes).
PM> We could also have our own random number generator, with our own random
PM> seed, in order to not interfere with the standard one.
PM> In fact, some randomization is desirable for a form boundary, but the
PM> effective number suite is not so important.
To my mind, this solution is the best one. We can use a modified PRNG
example from POSIX.1-2002:
unsigned long random_seed = (unsigned int)time(NULL)+randomizer++);
int Curl_rand_r(unsigned long *seed)
{
*seed = *seed * 1103515245 + 12345;
return ((unsigned)(*seed/65536) % 32768);
}
Now replace all calls to rand() with Curl_rand_r(&random_seed) - and
we have a completely autonomous random numbers generator.
-- Best regards, Tetetest mailto:tetetest_at_rambler.ruReceived on 2009-06-13