Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren0
why rand function keep returning 41 or same value as output?
we can use this code to generate random number but i don't know how it works? #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int a; srand ( time(NULL) ); a = rand(); printf("%d",a); return 0; }
2 Antworten
+ 5
If you don't randomize the seed using srand, your rand function will always return the same number. That's why you have to do this