0

When I run the code numbers are always the same positions. For example, the output is always:

1 1 1 0 
0 0 0 0 
1 1 0 1 (x=3 y=4)

How can I change the locations of these numbers?

int main(int argc, const char * argv[]) {
    int i, j, m, n;

    printf("Matrix'in X eksenini giriniz: ");
    scanf("%d", &m);

    printf("Matrix'in Y eksenini giriniz: ");
    scanf("%d", &n);

    for(i = 0; i < m; i++) {
        for(j = 0; j < n; j++) {
            printf("%d ", rand()%2);
        }
        printf("\n");
    }
    return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 3
    You need to call `srand` before using `rand`. See also [this question](https://stackoverflow.com/questions/7343833/srand-why-call-it-only-once). – user3386109 Mar 05 '20 at 11:02
  • 4
    You need to seed the random number generator by calling `srand()`. One barely adequate possibility is `srand(time(0));` — and including ``. That gives you a different sequence as long as you don't call the program twice in one second, but the output is not very random because the seed is predictable. – Jonathan Leffler Mar 05 '20 at 11:02

0 Answers0