permutation function

Sep 16, 2012 at 10:45am
Hi, I want to write a function that will choose say m of the members of an array with n members, randomly. Could anyone help please?
Last edited on Sep 16, 2012 at 10:56am
Sep 16, 2012 at 11:35am
I think you should use expression std::rand() % n in a loop with m iterations.
Sep 16, 2012 at 11:45am
1. Shuffle the array randomly http://en.cppreference.com/w/cpp/algorithm/random_shuffle
2. Pick the first 'm' members
Sep 21, 2012 at 12:03pm
Thanks JLBorges, it solved my problem.
Topic archived. No new replies allowed.