MantisBT - CMake
View Issue Details
0009851CMakeCMakepublic2009-11-06 03:142010-11-05 12:13
Marcel Loose 
David Cole 
normalminoralways
closedfixed 
CMake-2-6 
CMake 2.8.3 
0009851: string(RANDOM) does not produce random string within a CMake run
I expected that string(RANDOM...) would produce a different string each
time it is invoked. Turns out that this string is only different between
different cmake runs. This is not what I expected. IMHO this is a bug,
either in the code, or in the documentation.

$ cat ../CMakeLists.txt
project(Dummy NONE)
cmake_minimum_required(VERSION 2.6)
string(RANDOM a)
string(RANDOM b)
message(STATUS "a=${a}")
message(STATUS "b=${b}")

$ cmake ..
-- a=PgDGb
-- b=PgDGb
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/loose/cmake/build
According to David Cole this is caused by the fact that the random generator is seeded on every call to string(RANDOM...) using a one-second resolution time value as seed.

Solution: only seed the random generator once.
No tags attached.
Issue History
2009-11-06 03:14Marcel LooseNew Issue
2009-11-06 09:27Bill HoffmanStatusnew => assigned
2009-11-06 09:27Bill HoffmanAssigned To => David Cole
2009-11-06 10:20David ColeNote Added: 0018362
2009-11-06 10:20David ColeStatusassigned => resolved
2009-11-06 10:20David ColeResolutionopen => fixed
2010-11-05 12:13Marcel LooseNote Added: 0022899
2010-11-05 12:13Marcel LooseStatusresolved => closed
2010-11-05 12:13Marcel LooseFixed in Version => CMake 2.8.3

Notes
(0018362)
David Cole   
2009-11-06 10:20   
Fix issue 0009851 - 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.

Source/cmStringCommand.cxx Revision: 1.32
Source/cmStringCommand.h Revision: 1.31
Tests/CMakeTests/StringTestScript.cmake Revision: 1.3
(0022899)
Marcel Loose   
2010-11-05 12:13   
I verified that this is now OK with 2.8.3.