不重复随机序列

#include <iostream>
#include <time.h>
#include <stdlib.h>
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<length;i++)
{
exchange(a[i],a[random(i,length)]);
}

for (int i=0;i<length;i++)
{
cout<<a[i]<<"";
}
system("pause");
return 0;
}
原文地址:https://www.cnblogs.com/tiandsp/p/2356262.html