PHP Tip using the rand()

Before using the rand() function, it’s a good idea to seed the random number generator first. This can be done with the srand() function. Its most common form is:

srand((double)microtime() * 1000000);

If you don’t take this step before using rand(), it’s possible – likely, even – that your “random” numbers will not necessarily be random.

Comments are closed.