OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 12 Aug 2013 02:46:33 -0500How to generate a random permutation?http://answers.opencv.org/question/5223/how-to-generate-a-random-permutation/I am using opencv2 to generate a random permutation.
For example, generate a random permutation with number ranging from 1 to 10. I have tried many times, howerver ,I couldn't realize it it.
Would be great to get your help. I appreciate any suggestions
Sat, 15 Dec 2012 08:07:04 -0600http://answers.opencv.org/question/5223/how-to-generate-a-random-permutation/Answer by SR for <p>I am using opencv2 to generate a random permutation. <br>
For example, generate a random permutation with number ranging from 1 to 10. I have tried many times, howerver ,I couldn't realize it it. <br>
Would be great to get your help. I appreciate any suggestions</p>
http://answers.opencv.org/question/5223/how-to-generate-a-random-permutation/?answer=18627#post-id-18627 #include <algorithm> // std::random_shuffle
#include <vector> // std::vector
#include <cstdlib> // std::rand, std::srand
vector<int> permutation = 1, 2, 3, ..., 10
std::random_shuffle(permutation.begin(), permutation.end());
Mon, 12 Aug 2013 02:46:33 -0500http://answers.opencv.org/question/5223/how-to-generate-a-random-permutation/?answer=18627#post-id-18627Answer by Adi for <p>I am using opencv2 to generate a random permutation. <br>
For example, generate a random permutation with number ranging from 1 to 10. I have tried many times, howerver ,I couldn't realize it it. <br>
Would be great to get your help. I appreciate any suggestions</p>
http://answers.opencv.org/question/5223/how-to-generate-a-random-permutation/?answer=5246#post-id-5246You can use the [Boost Permutation Iterator](http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/permutation_iterator.html) or use OpenCV's [`randShuffle()`](http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?highlight=rng#randshuffle) (there is an example of how to use it in the samples under `samples\cpp\kmeans.cpp`).
Sun, 16 Dec 2012 10:07:50 -0600http://answers.opencv.org/question/5223/how-to-generate-a-random-permutation/?answer=5246#post-id-5246