mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-02 04:09:33 -05:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user