Random random seeds

This is a discussion on Random random seeds within the C++ Programming forums, part of the General Programming Boards category; Code:
srand(time(NULL));
srand(rand() % 5000);
Would that be more random than just calling the time seed alone?...

BASIC's system, once compiled, would always select the same numbers. Its just that you wouldn't have to specify the numbers. Theoretically, using that code shouldn't make much of a difference, but go ahead and try it. Once something is random, it's about as random as it's going to get. It's like if I shoot something, it's dead. I can't shoot it again to make it more dead.

Wouldn't frenchfry's way actually be alot less random? Using the time as a seed will always give you a different seed than before, as time goes forward all the time. But with his, you'd only have 5000 (or whatever number he chooses) different seeds, and thus, it would give out the same numbers every 5000 times you run the program, or so. Ofcourse it might choose the same number more often, but you know what I mean.

rand() is a psuedo-random number generator. It will always produce the same sequence of "random" numbers with a given seed.
srand() take an unsigned int as its argument so the total possible number of seeds is ~65500 for a 2-byte int and ~4,300,000,000 for a 4-byte int (which is more likely now days). Which means, it is possible to have the same seed every now and again but rather unlikely. As pointed out, if you mod by 5000, you have just cut down the total possible seeds to only 5000.

French, in most cases srand() and rand() provide sufficently random number for an application.

Also, if you WERE to come up with a completely random random number generator, you would most likely get a PhD out of it. The security and encryption industry is always looking for more random random numbers.

french, I can tell you very simply why that would fail to produce a more random number.

The only unique number given to srand is time(). Therefore, there is an upper limit on randomness set at srand(unsigned(time(NULL)))

Think about it this way:

For any given value returned by time(NULL), or any given set of values returned by multiple calls to time(NULL), the pseudo-random number generator can only be seeded in one manner. Subsequent calls to rand() will return numbers based only on this value or set of values.

If anyone were to write an algorithm that returned truly random numbers, it would not take a seed value. But this is beyond the scope of modern computer science. This is how random numbers tie in with encryption. Due to the ones and zeros nature of a computer, any random pattern of numbers is simply an ordered pattern of numbers whose order has been obfusciated beyond the casual appearance of a pattern.