random matrix generator - URGENT

Hi, I wrote a function to generate a random matrix of 0 and 1's. When I run the program by F5 program always generates matrix of all ones. However, ıf I go through step by step by F10 then ıt produces more random looking matrices. Could anyone help me please?

Here's the code:

void generate_network(arr[][], n)
{
for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {

srand(time(0));
int num = rand() %100;

if (num > 50)
arr[i][j] = 1;

else
arr[i][j] = 0;
}
}
}
Call srand() once, not every time you want a number.
Thank you very much. This helped :)
Topic archived. No new replies allowed.