不重复随机序列

#include 
#include
#include
using namespace std;

int random(int a,int b)
{
srand(NULL);
return rand()%(b-a)+a;
}

void exchange(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}

int main()
{
int a[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14};
int length=sizeof(a)/sizeof(int);
for (int i=0;i {
exchange(a[i],a[random(i,length)]);
}

for (int i=0;i {
cout<"";
}
system("pause");
return 0;
}

转载于:https://www.cnblogs.com/tiandsp/archive/2012/02/17/2356262.html

你可能感兴趣的:(不重复随机序列)