Seems like a bunch of nonsense to me. I just call rand() and seed it with
Code:
srand( (unsigned)time( NULL) );
If I want something more random than that, I seed the random number generator using time, then call rand() repeatedly to generate an array of random seed values. I'll use rand() to select one of the seed values from the array as follows
Code:
srand( seed_array[rand()&0xF] );
I'll also throw random bitwise operations in there
Code:
value = rand();
if(value & (rand() & 0xF))
value <<= rand()&0xF;
else
value >>= rand()&0xF;
At some point this has to produce something that is about as close to true random as you can possibly get.
Ugh, no. Your last sentence isn't even remotely true.
First of all, rand() is often a
very poor quality PRNG. IIRC, the C standard places basically no requirements on it, so you really have no idea what you're getting without inspecting the implementation. Also, RAND_MAX is often quite small, limiting the range of numbers that will be produced.
Second, changing the seed (or even how you produce the seed)
has no effect whatsoever on the quality of the PRNG. Each seed value produces a distinct sequence of numbers, and will always product that sequence when the same seed is set. Changing the seed changes the sequence of numbers, not the distribution.
Finally, doing bitwise operations isn't magic that makes things better. In fact, in the code snippet you posted, you're
removing bits of randomness, and actually making the distribution
worse.
Generating random numbers isn't a simple topic, and it's a very mathy topic. If you just need some numbers, rand() or whatever your language provides should be fine. If you're doing something where the quality of the numbers matters, or for whatever reason you thing the basic language PRNG isn't good enough, you should switch to a better PRNG like Mersenne Twister. If you're doing something where the quality
really matters, you need to be using a cryptographically secure generator like /dev/random or a hardware RNG.