summaryrefslogtreecommitdiffstats
path: root/Source/cmStringCommand.cxx
diff options
context:
space:
mode:
authorDavid Cole <david.cole@kitware.com>2009-11-06 15:07:10 (GMT)
committerDavid Cole <david.cole@kitware.com>2009-11-06 15:07:10 (GMT)
commitd6fe0438c1d5c6ecd5ebc0377781175ce14ac251 (patch)
tree7ac99f9ad88911211a8c003f2f19d2b4754f1543 /Source/cmStringCommand.cxx
parent10762565e95b9cac08b7a0b643fdc5bf39bb2b96 (diff)
downloadCMake-d6fe0438c1d5c6ecd5ebc0377781175ce14ac251.zip
CMake-d6fe0438c1d5c6ecd5ebc0377781175ce14ac251.tar.gz
CMake-d6fe0438c1d5c6ecd5ebc0377781175ce14ac251.tar.bz2
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.
Diffstat (limited to 'Source/cmStringCommand.cxx')
-rw-r--r--Source/cmStringCommand.cxx17
1 files changed, 16 insertions, 1 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 2313853..3bd47a4 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -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 ++ )