The difficulty of random generation is how to avoid collisions, some people say with md5,guid these mechanisms ah, of course, but as accounts, look at the chaos, and the generation of bits too long. This method only need to solve the concurrent collisions within 1 seconds, because the fixed head is Unixtime time, accurate to the second, more than 1 seconds, the head of the time must have changed. At the same time this method can also be generated by the user random order number. The test condition is to create 10,000 random accounts (in milliseconds), 0 collisions, and 100,000 about 0-3 collisions with a loop. No internet company should be able to create so many accounts at the same time, so it's enough to deal with the size of billions of PV. ~~~.java//automatically generate random username//test, loop Create 10,000 random accounts, 0 collisions, 100,000 about 0-3 collisions, enough to cope with future billions of level pvprivate function Genusernumber () {$chars = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "; $username =" "; for ($i = 0; $i < 6; $i + +) {$username. = $chars [Mt_rand (0, strlen ($chars))];} Return Strtoupper (Base_convert (Time ()-1420070400, Ten)). $username;} ~~~