Here's an example of the Fisher-Yates shuffle algorithm:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void FYshuffle (int *ray, int len) {
int i, tmp, x;
for (i=len-1; i>1; i--) {
x = rand()%i;
if (x==i) continue;
// now swap
tmp = ray[i];
ray[i] = ray[x];
ray[x] = tmp;
}
}
int main(void) {
int ray[10] = {0,1,2,3,4,5,6,7,8,9}, i;
srand(time(0));
FYshuffle(ray,10);
for (i=0;i<10;i++) printf("%d\n",ray[i]);
return 0;
}
But you can't do that with this:
Code:
char Names [9] [15];
However, you can do it with this:
Which can be initialized the same way. You'd then need to modify the shuffle function to work with a char *ray[] (which means changing the first parameter and the type of the tmp variable).