dimanche 7 juin 2020

Why does the first random value just increase every time I run the code?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[]) {

    srand((unsigned)time(NULL));
    printf("%d\n", rand()%100+1);
    printf("%d", rand()%100+1);

    return 0;
}

I've run this many times and each time the first value just increased steadily, like 2 5 9 17 24 30 ..... 91 97 3 7 12 (but the value is always different). Strangely, the second value performed normally, what could be the reason?

I'm using Dev-C++ and TDM-GCC 4.9.2




Aucun commentaire:

Enregistrer un commentaire