[Cmake-commits] [cmake-commits] david.cole committed cmStringCommand.cxx 1.31 1.32 cmStringCommand.h 1.30 1.31
cmake-commits at cmake.org
cmake-commits at cmake.org
Fri Nov 6 10:07:12 EST 2009
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv24573/Source
Modified Files:
cmStringCommand.cxx cmStringCommand.h
Log Message:
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.
Index: cmStringCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmStringCommand.cxx,v
retrieving revision 1.31
retrieving revision 1.32
diff -C 2 -d -r1.31 -r1.32
*** cmStringCommand.cxx 2 Oct 2009 18:51:43 -0000 1.31
--- cmStringCommand.cxx 6 Nov 2009 15:06:59 -0000 1.32
***************
*** 701,704 ****
--- 701,707 ----
}
+ static bool seeded = false;
+ bool force_seed = false;
+ int seed = (int) time(NULL);
int length = 5;
const char cmStringCommandDefaultAlphabet[] = "qwertyuiopasdfghjklzxcvbnm"
***************
*** 724,727 ****
--- 727,736 ----
alphabet = args[i];
}
+ else if ( args[i] == "RANDOM_SEED" )
+ {
+ ++i;
+ seed = atoi(args[i].c_str());
+ force_seed = true;
+ }
}
}
***************
*** 745,749 ****
std::vector<char> result;
! srand((int)time(NULL));
const char* alphaPtr = alphabet.c_str();
int cc;
--- 754,764 ----
std::vector<char> result;
!
! if (!seeded || force_seed)
! {
! seeded = true;
! srand(seed);
! }
!
const char* alphaPtr = alphabet.c_str();
int cc;
Index: cmStringCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmStringCommand.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -C 2 -d -r1.30 -r1.31
*** cmStringCommand.h 28 Sep 2009 15:42:49 -0000 1.30
--- cmStringCommand.h 6 Nov 2009 15:06:59 -0000 1.31
***************
*** 90,94 ****
" string(STRIP <string> <output variable>)\n"
" string(RANDOM [LENGTH <length>] [ALPHABET <alphabet>]\n"
! " <output variable>)\n"
"REGEX MATCH will match the regular expression once and store the "
"match in the output variable.\n"
--- 90,94 ----
" string(STRIP <string> <output variable>)\n"
" string(RANDOM [LENGTH <length>] [ALPHABET <alphabet>]\n"
! " [RANDOM_SEED <seed>] <output variable>)\n"
"REGEX MATCH will match the regular expression once and store the "
"match in the output variable.\n"
***************
*** 116,120 ****
"characters from the given alphabet. Default length is 5 "
"characters and default alphabet is all numbers and upper and "
! "lower case letters.\n"
"The following characters have special meaning in regular expressions:\n"
" ^ Matches at beginning of a line\n"
--- 116,121 ----
"characters from the given alphabet. Default length is 5 "
"characters and default alphabet is all numbers and upper and "
! "lower case letters. If an integer RANDOM_SEED is given, its "
! "value will be used to seed the random number generator.\n"
"The following characters have special meaning in regular expressions:\n"
" ^ Matches at beginning of a line\n"
More information about the Cmake-commits
mailing list