As we learned in Random Stupidity, developers don't really trust rand(), random(), Random.GetNext(), etc. Nor should they. The documentation, after all, clearly states that the function "generates a pseudo-random number." That's right, pseudo. Who wants pseudo?

The neat thing about pseudo-randomness is that, if you think about it -- and you don't think too much about it -- you can actually generate a real random number by pseudo-randomizing a pseudo-randomizer a pseudo-random number of times. It's kind like how two wrongs (either wrongly done for the right reason or rightly done for the wrong reason) make a right. Really, it's simple math.

Jacob's predecessor was well aware of this fact, and devised a very clever way to generate extremely random numbers: by increasing the entropy.

void GenerateRandom(unsigned char Val[16], unsigned long seed)
{
   int i;

   // Initialize randomizer
   srand(seed); 

   // This really doesn't have enough entropy....
   for(i=0;i<(rand() & 16);i++) srand(rand());

   // Get the val
   for(i=0;i<16;i++) Val[i]=(char)(( rand() >> 7) & 0x00FF); 
}

 

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!