Two choices:
1) Initialize the array sequentially: [0,1,2,3,4], then shuffle the array by:
for (int i = 0; i < MAX; i++)
array[i] = i;
for (int i = 0; i < MAX; i++) {
int tmp = array[i];
int r = arc4random() % MAX;
array[i] = array[r];
array[r] = tmp;
}
You can shuffle several times if you find it's needed.
2) Or initialize the array randomly but make sure you don't duplicate numbers.
There are several different ways to do that, but the most obvious is just keep an array of booleans to indicate whether a number has been used yet, and keep calling random until you get an answer that isn't yet used. Then put that number in the array and mark it as used in your boolean array.
for (int i = 0; i < MAX; i++)
used[i] = false;
for (int i = 0; i < MAX; i++) {
int r = arc4random() % MAX;
while (used[r])
r = arc4random() % MAX;
array[i] = r;
used[r] = true;
}
Execution time is a lot longer on this second method since you have to keep calling random until you choose the number you haven't chosen yet (but if your array is small, it will terminate in a fairly short period of time).