mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
Fix issue #9851 - only seed the random number generator on the first call to STRING(RANDOM or if given the new RANDOM_SEED argument. Add test and documentation of new argument.
This commit is contained in:
@@ -700,6 +700,9 @@ bool cmStringCommand
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool seeded = false;
|
||||
bool force_seed = false;
|
||||
int seed = (int) time(NULL);
|
||||
int length = 5;
|
||||
const char cmStringCommandDefaultAlphabet[] = "qwertyuiopasdfghjklzxcvbnm"
|
||||
"QWERTYUIOPASDFGHJKLZXCVBNM"
|
||||
@@ -723,6 +726,12 @@ bool cmStringCommand
|
||||
++i;
|
||||
alphabet = args[i];
|
||||
}
|
||||
else if ( args[i] == "RANDOM_SEED" )
|
||||
{
|
||||
++i;
|
||||
seed = atoi(args[i].c_str());
|
||||
force_seed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !alphabet.size() )
|
||||
@@ -744,7 +753,13 @@ bool cmStringCommand
|
||||
const std::string& variableName = args[args.size()-1];
|
||||
|
||||
std::vector<char> result;
|
||||
srand((int)time(NULL));
|
||||
|
||||
if (!seeded || force_seed)
|
||||
{
|
||||
seeded = true;
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
const char* alphaPtr = alphabet.c_str();
|
||||
int cc;
|
||||
for ( cc = 0; cc < length; cc ++ )
|
||||
|
||||
Reference in New Issue
Block a user