Difference between revisions of "CPP/STL/RandomData"
From ProgrammingExamples
< CPP
FirstPerson (Talk | contribs) (→Generate.cpp) |
Daviddoria (Talk | contribs) |
||
| Line 22: | Line 22: | ||
return 0; | return 0; | ||
} | } | ||
| + | |||
| + | </source> | ||
| + | |||
| + | ==CMakeLists.txt== | ||
| + | <source lang="cmake"> | ||
| + | cmake_minimum_required(VERSION 2.6) | ||
| + | |||
| + | PROJECT(Generate) | ||
| + | |||
| + | ADD_EXECUTABLE(Generate Generate.cpp) | ||
</source> | </source> | ||
Latest revision as of 08:24, 26 February 2011
Generate.cpp
#include <iostream> #include <vector> #include <algorithm> struct RandFloat{ float operator()() { return rand()/(float)RAND_MAX; } }; int main (int argc, char *argv[]) { //create some random data std::vector<float> data(10,0.0f); //from data.begin to end, generate random floats for each index std::generate(data.begin(), data.end(), RandFloat()); for(unsigned int i = 0; i < data.size(); i++){ std::cout << data[i] << std::endl; } return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(Generate) ADD_EXECUTABLE(Generate Generate.cpp)