void random(int a[], int n) {
int index, tmp, i;
srand(time(NULL));
for (i = 0; i <n; i++)
{
index = rand() % (n - i) + i;
if (index != i)
{ tmp = a[i];
a[i] = a[index];
a[index] = tmp;
}
}
}
注:a[]为需要打乱的数组 n是数组大小
void random(int a[], int n) {
int index, tmp, i;
srand(time(NULL));
for (i = 0; i <n; i++)
{
index = rand() % (n - i) + i;
if (index != i)
{ tmp = a[i];
a[i] = a[index];
a[index] = tmp;
}
}
}
注:a[]为需要打乱的数组 n是数组大小