The difficulty in random generation is how to avoid collisions. Some people say to use mechanisms such as md5 and GUID. Of course you can, but as an account, it looks messy, and the number of generated digits is too long.
This method only needs to solve concurrent collisions within 1 second, because the fixed head uses unixtime time, which is accurate to the second. If it exceeds 1 second, the time of this head must have changed. At the same time, this method can also generate random order numbers for users.
The test condition is to use a loop to create 10,000 random accounts (millisecond level), with 0 collisions, and 100,000 accounts with approximately 0-3 collisions. There should be no Internet company that would create so many accounts at the same time in an instant, so it is enough to handle a scale of billions of PV.
// Automatically generate random usernames
// Test, create 10,000 random accounts in a loop, 0 collisions, 100,000 about 0-3 collisions, enough to cope with billions of PV in the future
private function genUserNumber() { $chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $username = ""; for ( $i = 0; $i < 6; $i++ ) { $username .= $chars[mt_rand(0, strlen($chars))]; } return strtoupper(base_convert(time() - 1420070400, 10, 36)).$username; }

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
