Use PHP to batch generate random user names

Source: Internet
Author: User
Born 6 ~ There are several 16-bit user names. The most important thing is text control. the condition for a colleague is to have a string package. It mainly contains three programs. Procedure 1: Extract data randomly from the dictionary and write it into a new file. (1.php )? Php/* Dictionary File

Born 6 ~ There are several 16-bit user names. The most important thing is text control. the condition for a colleague is to have a string package. It mainly contains three programs.

Procedure 1: Extract data randomly from the dictionary and write it into a new file. (1.php)

/* Extract random values from dictionary files */

$ File1 = './Words. dic ';
$ File2 = './common_pass_mini.dic ';
$ File3 = './Sys_Month_Date.Dic ';
$ Rfile = './5. dic ';
$ N = 2000;

// Extract the dictionary
$ Basef = file ($ file1 );
$ Extf = file ($ file2 );
$ Extf2 = file ($ file3 );
$ Bf_sum = (count ($ basef)-1 );
$ Ef_sum = (count ($ extf)-1 );
$ Ef2_sum = (count ($ extf2)-1 );

// Obtain the random user name
For ($ I = 0; $ I <$ n; $ I)
{
$ Bn = crand (0, $ bf_sum );
$ En = crand (0, $ ef_sum );
$ En2 = crand (0, $ ef2_sum );
$ Name = $ basef [$ bn]. '_'. $ extf [$ en];
$ Name = str_replace ('\ r \ n', '', $ name );
$ All_name [] = $ name;
}

// Write the file
$ Result = implode ('\ r \ n', $ all_name );
$ Fp = fopen ($ rfile, 'A') or die ('open $ rfile failed ');
If (fwrite ($ fp, $ result )){
Echo 'write user succeed! ';
} Else {
Echo 'write user failed ';
}

// Natural Random number function
Function crand ($ start, $ end)
{
Return mt_rand ($ start, $ end );
}
?>

Procedure 2: merge the results of several inherent documents above. (2.php)

/* Merge all natural results */

$ Result_file = './result. dic ';

$ Fp = fopen ($ result_file, 'A') or die ('open $ result_file failed ');

// Merge 1.dic ~ 5. dic
For ($ I = 1; $ I <= 5; $ I)
{
$ Cur_file = file_get_contents ($ I. '. dic ');
Fwrite ($ fp, $ cur_file );
}

// Merge 10.dic ~ 11. dic
For ($ I = 10; $ I <= 11; $ I)
{
$ Cur_file = file_get_contents ($ I. '. dic ');
Fwrite ($ fp, $ cur_file );
}
Fclose ($ fp );
Echo 'write succeed ';

?>

Procedure 3: filter duplicate values and do not belong to 6 ~ Between 16 values and the ultimate outcome (3.php)

/* Inherent ultimate outcome */

$ File = './result. dic ';
$ Target = './target. dic ';

// Remove duplicate values
$ Files = file ($ file );
$ Files = array_unique ($ files );

// Determine whether the value is greater than 6 bits and less than 16 bits
$ Sum = count ($ files );
For ($ I = 0; $ I <$ sum; $ I)
{
If (strlen ($ files [$ I])> = 6 & strlen ($ files [$ I]) <= 16 ){
$ Rs [] = $ files [$ I];
} Else {
Continue;
}
}

// Write it into the target file
$ Result = implode ('', $ rs );
$ Fp = fopen ($ target, 'A') or die ('open $ target failed ');
Fwrite ($ fp, $ result );
Echo 'write succeed ';

?>

The basic work is done manually, with random usernames created above. haha, make sure your application is sufficient.

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.