Bug 867769 - NS_MakeRandomString generates the same string when called twice within the same second. r=bsmedberg

This commit is contained in:
Dave Hylands 2013-05-02 14:50:11 -07:00
parent 31c5b9121f
commit a6b2e561da

View File

@ -251,8 +251,12 @@ void NS_MakeRandomString(char *aBuf, int32_t aBufLen)
{
// turn PR_Now() into milliseconds since epoch
// and salt rand with that.
double fpTime = double(PR_Now());
srand((unsigned int)(fpTime * 1e-6 + 0.5)); // use 1e-6, granularity of PR_Now() on the mac is seconds
static unsigned int seed = 0;
if (seed == 0) {
double fpTime = double(PR_Now());
seed = (unsigned int)(fpTime * 1e-6 + 0.5); // use 1e-6, granularity of PR_Now() on the mac is seconds
srand(seed);
}
int32_t i;
for (i=0;i<aBufLen;i++) {