A simple function that uses php to generate random numbers or random strings. You can modify the characters in the $ chars variable to indicate the length of a number or string. The Code is as follows:
The Code is as follows:
/**
* Generate random strings
*
* Generates a random string of the specified length and returns it to the user.
*
* @ Access public
* @ Param int $ len: number of digits of the string generated
* @ Return string
*/
Function randstr ($ len = 6 ){
$ Chars = 'abcdefghijklmnopqrstuvwxyz
Abcdefghijklmnopqrstuvwxyz0123456789 -@#~ ';
// Characters to build the password from
Mt_srand (double) microtime () * 1000000 * getmypid ());
// Seed the random number generater (must be done)
$ Password = '';
While (strlen ($ password) <$ len)
$ Password. = substr ($ chars, (mt_rand () % strlen ($ chars), 1 );
Return $ password;
}