| Question : | Why doesn't rand give random numbers?
| | Answer : | I use the following code
$iRandom = rand(0,100);
But I dotn get random numbers, whats wrong?
You have not RTFM'ed good enough, if you read the man page for rand carefully you will find a line that states:
"Remember to seed the random number generator before use with srand()."
So the proper code would be:
srand((double)microtime()*1000000);
$iRandom = rand(0,100);
As an alternative you can use mt_rand which should generate more random, numbers. Read more about that here:
http://www.php.net/manual/en/function.mt-rand.php
| | |