The third argument to memcpy is the number of bytes to copy so you want:
Code:
memcpy(RandomArray, OriginalArray, NumElements * sizeof(RandomArray[0]));
I'm suspicious of your use of NumElements - 1. Typically we don't want the - 1 because we are using the < operator and therefore for an array with 5 elements we get:
Code:
for (int index = 0; index < 5; index++) {
// index goes from 0 to 4
OriginalArray[index] = rand() % NumElements;
}
while with - 1 we get:
Code:
for (int index = 0; index < 5 -1; index++) {
// Index goes from 0 to 3
OriginalArray[index] = rand() % NumElements;
}