如何精确产生不重复随机数,
比如在10范围内产生10个不重复的数字
for(i=0; i<10; ++i){ num = rand() % 10;}
#include <vector>#include <iostream>#include <algorithm>#include <ctime>using namespace std;int VecRandom(int num){ return rand() % num;}int main(){ srand ( unsigned ( time (NULL) ) ); int Array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; vector<int> Vec( Array, Array + _countof( Array ) ); random_shuffle( Vec.begin(), Vec.end(), VecRandom); copy ( Vec.begin(), Vec.end(), ostream_iterator<int> (cout, "\n") ); return 0;}