PHP generates a random password function, which can be used to generate a random number or generate a random password. if you need a random password, refer to the function code below.
// PHP generates a random number and password function (six digits by default) function randStr ($ len = 6, $ format = 'all') {switch ($ format) {case 'all ': $ chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 -@#~ '; Break; case 'char': $ chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz -@#~ '; Break; case 'number': $ chars = '000000'; break; default: $ chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 -@#~ '; Break;} mt_srand (double) microtime () * 1000000 * getmypid (); $ password = ''; while (strlen ($ password) <$ len) {$ password. = substr ($ chars, (mt_rand () % strlen ($ chars), 1);} return $ password ;}