Originally Posted by
userxbw
not going to argue but I am taking into consideration as well that this has a fix amount of numbers, being only two, 0 or 1, which doesn't leave much room to play. seems a little redundant to me.
The PRNG behind srand and rand, whatever the implementation, has a finite range to begin with. You're confusing the range of the PRNG with the notion of simulating randomness. If you don't explicitly seed the PRNG, it will be as if it were seeded with srand(1), hence the result of running the PRNG will be the same on each run of the program. This is great for having consistent input during testing, but is typically bad when you actually want to run the program in "production".
If you don't believe me, compile this program once and run it three times, waiting for some time between each run:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i;
for (i = 0; i < 10; ++i)
{
printf("%d ", rand() % 2);
}
putchar('\n');
return 0;
}
Then compile this program once and run it three times, waiting for some time between each run:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i;
srand((int)time(0));
for (i = 0; i < 10; ++i)
{
printf("%d ", rand() % 2);
}
putchar('\n');
return 0;
}