Originally Posted by
godofal
second, i tried at lesson 3 the random option, but i cant get it really random, its semi random, in wich i get the same numbers over and over again.
i know computers aren't really capable of generating random numbers, but i think it should be a litle more random every time i open the program...
i saw the rest of the lesson, im just curious about why it gives me every time the same number sequency...
That's how a random number generator works:
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int i;
//srand(time(NULL));
for (i=0;i<100;i++)
printf("%d ",rand());
return 0;
}
This will produce the same pattern of 100 numbers every time unless you uncomment the "srand()" line -- this seeds the Random Number Generator with a "random" value, meaning the sequence will always be different (since the time is never the same).
You don't need to use srand() more than once, at the beginning of the program, before you call rand(). Doing it more than once could actually result in less random numbers (tho it may not, depending on how you do it).