Why does this result in the same array every time i run it?
int arr[100];
for (int i = 0; i < 100; i++) {
arr[i] = rand() % 11 + (-5);
}
Why does this result in the same array every time i run it?
int arr[100];
for (int i = 0; i < 100; i++) {
arr[i] = rand() % 11 + (-5);
}
You need to seed the random number generator, for example with the current time.
#include <time.h>
#include <stdlib.h>
srand(time(NULL));
Use std::srand(std::time(0));
to set the random seed. For reproducible results, use the same seed, see http://en.cppreference.com/w/cpp/numeric/random/srand.