mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 867769 - NS_MakeRandomString generates the same string when called twice within the same second. r=bsmedberg
This commit is contained in:
parent
31c5b9121f
commit
a6b2e561da
@ -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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user