#include "stdafx.h"
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <time.h>
#include<list>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
srand((unsigned)time(NULL));
list<int>::iterator it;
list<int> l;
int begin, end;
int sum;
cout << "输入数字范围([n,m]):";
cin >>begin>>end;
cout << "输入随机数个数:";
cin >> sum;
if ( (end<0)||(begin<0)||(begin >end)|| (sum>end))
{
cout << "范围错误";
cout << endl;
system("pause");
return 0;
}
else
{
while (l.size() < sum)
{
l.push_back(rand() % (end - begin + 1) + begin);
l.sort();
l.unique();
}
cout << "结果:";
}
for (it = l.begin(); it != l.end(); it++)
{
cout << *it << ' ';
}
cout << endl;
system("pause");
return 0;
}