PHP random user name account generation-php Tutorial

Source: Internet
Author: User
PHP random user name account generation
The difficulty of random generation is how to avoid collision. some people say that md5 and GUID mechanisms are used. of course, they can. but as an account, there are chaos and the number of digits generated is too long. This method only needs to solve the concurrent collision within 1 second, because the fixed header uses the unixtime time, accurate to seconds, more than 1 second, the time of this header must change. This method can also be used to generate random order numbers. The test condition is that 10 thousand random accounts (in milliseconds) are created cyclically, with 0 collisions and 0.1 million with about 0-3 collisions. No internet company will create so many accounts at the same time, so it is enough to cope with the scale of billions of PVS .~~~. Java // automatically generate a random user name // Test, create 10 thousand random accounts cyclically, with 0 collisions, and 0.1 million collisions with about 0-3, which is sufficient to cope with the next billions of PVprivate function genUserNumber () {$ chars = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $ username = ""; for ($ I = 0; $ I <6; $ I ++) {$ username. = $ chars [mt_rand (0, strlen ($ chars)];} return strtoupper (base_convert (time ()-1420070400, 10, 36 )). $ 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.