C++ way to randomly select M numbers
Note the extensive use of STL.
1 2 const short NMAX = 49; 3 const short M = 6; 4 5 std::vector<short> v; 6 for (short i(0); i < NMAX; ++i) 7 v.push_back(i + 1); 8 9 random_shuffle(v.begin(), v.end()); 10 copy(v.begin(), v.begin() + M, std::ostream_iterator<short>(std::cout, " "));