for(i = 0; i < n; i++){
srand(time(NULL));
printf("%d ", time(NULL));
for(j = 0; j < (n-1); j++){
a[i][j] = rand();
}
}
I try to generate random numbers, but they are the same… I try srand(i * time(NULL)). No matter..
What should i do?
Array declaration:
int** a;
int i;
printf("Enter array size: ");
scanf("%d", &n);
a = (int**)calloc(n, sizeof(int));
for(i = 0; i < n; i++)
a[i] = (int*)calloc(n-1, sizeof(int));
Call
srand()outside of the loop. You are reseeding it every iteration.srand()seeds the random number generator so you get a different sequence of random numbers depending on the input. Your loop runs very fast, so the call totime(NULL)always returns the same value. You are resetting to the same random sequence with every iteration. As a general rule, only callsrand()once in your program.