mercredi 16 novembre 2022

The rand() function generate ridiculous numbers [closed]

I don't understand why rand() function is returning so ridiculous integers. The first 4 generated numbers seems to be ok, but what's going on after them?

There is fragment of code:

int i=0, j=0;
int tab[4][3];
srand(time(0));

    for(i;i<=3;i++) {
        for(j;j<=2;j++) {
            tab[i][j] = rand() % 50;
        }
    }


    for(i=0;i<=3;i++) {
        for(j=0;j<=2;j++) {
            printf("%d\t", tab[i][j]);
        }
        printf("\n");
    }

And the output is:

16      31      24
24      65535   -1068880744
-1068880744     65535   1358574848
1358574848      1323076347      -1068880848



Aucun commentaire:

Enregistrer un commentaire