PHP has two different functions for generating random number, rand() and
mt_rand(), which is more random and faster than rand(). This example uses the
Random numbers – source code
The example generates a number in the range of 0 to maximum with maximum being the value returned by the mt_getrandmax() function.
Random strings – source code
The example generates a string of random numbers, uppercase and lowercase letters and other characters depending on the character types included. This is done by getting a random number in seven ASCII value ranges, three ranges for the “0-9”, “A-Z”, and “a-z” and then four more ranges for the other characters. These are then combined and added to the result until the requested number of characters has been obtained.