0

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; }

11th Jan 2018, 1:14 PM
alpha one
alpha one - avatar
3 Respostas
+ 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
11th Jan 2018, 1:26 PM
Dapper Mink
Dapper Mink - avatar