Generation of PHP random user name account

Source: Internet
Author: User
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;} ~~~
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.