Improve string(RANDOM) default seed

The naive time(0) seed is unique only within one second.  Instead try to
read a real source of entropy and otherwise fall back to a combination
of the process id and high-resolution time.
This commit is contained in:
Brad King
2011-05-17 10:07:26 -04:00
parent a77dfb6d64
commit e1b0a11dd4
3 changed files with 69 additions and 2 deletions
+2 -2
View File
@@ -770,7 +770,7 @@ bool cmStringCommand
static bool seeded = false;
bool force_seed = false;
int seed = (int) time(NULL);
int seed = 0;
int length = 5;
const char cmStringCommandDefaultAlphabet[] = "qwertyuiopasdfghjklzxcvbnm"
"QWERTYUIOPASDFGHJKLZXCVBNM"
@@ -825,7 +825,7 @@ bool cmStringCommand
if (!seeded || force_seed)
{
seeded = true;
srand(seed);
srand(force_seed? seed : cmSystemTools::RandomSeed());
}
const char* alphaPtr = alphabet.c_str();