PHP: rand() vs. mt_rand() – what is more accurate, what is faster?

After I was pointed out, that it would be better to use the PHP function mt_rand() instead of rand() for generating random numbers (because mt_rand() should be more accurate), I decided to investigate on that statement. But at first, where is the difference between rand() and mt_rand()?
By use of mt_rand() you can generate random numbers just like with the rand() function. The function call also looks equal on both functions. Though the PHP documentation says mt_rand() is up to 4-times faster and would be create more random/arbitrary numbers. By implication this would mean, that the rand() function creates inaccurate random numbers.
I was not aware of this problem, but after some googleing I discovered that there are a lot of people who think that mt_rand() is the better function. However I had to notice that most of the contributions which complain that rand() is not clean are a “little older”.
Often cited […]

Generate array of different/unique random numbers in PHP

Sometime it is necessary to generate a list of different random numbers. A possible usage scenario therefore could be a raffle where the winners should be choosen by chance, but every single user shouldn’t get more than one prize.
So in the following snippet, I’ll show you how to generate a list of different randoms in PHP.

//Create an array of numbers from which the randoms
//should be choosen. (For raffle: the list of user id’s)
$array = range($minimum, $maximum);

//Initialize the random generator
srand ((double)microtime()*1000000);

//A for-loop which selects every run a different random number
for($x = 0; $x < $numberOfRandoms; $x++)
//Generate a random number
$i = rand(1, count($array))-1;

//Take the random number as index for the array
$result[] = $array[$i];

//The chosen number will be removed from the array
//so it […]