C++产生不重复的随机数

#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>

using namespace std;
 
int main()
{
 srand(unsigned(time(NULL)));
 vector<int> myvector;
 vector<int>::iterator it;
 for (int i = 1; i <= 13; i++)
 {
  myvector.push_back(i);
 }
 
 random_shuffle(myvector.begin(), myvector.end());
 
 for (it = myvector.begin(); it != myvector.end(); ++it)
 {
  cout << " " << *it;
 }
}

你可能感兴趣的:(C++产生不重复的随机数)