Generate random usernames in batches using PHP

Source: Internet
Author: User
Generate 6 ~ There are several 16-bit user names, mainly text operations. The premise is that there must be a string package. It mainly contains three programs. Procedure 1: Extract data randomly from the dictionary and write a new file. (1.php )? Php * extracts random values from dictionary files * $ file1.Words. dic; $ file2.common _ pass_mini.dic; $ file3 generates 6 ~ There are several 16-bit user names, mainly text operations. The premise is that there must be a string package. It mainly contains three programs.

Procedure 1: Extract data randomly from the dictionary and write 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 a 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 ';
}

// Generate a random number function
Function crand ($ start, $ end)
{
Return mt_rand ($ start, $ end );
}
?>


Procedure 2: merge the results of the preceding files. (2.php)

/* Merge all generated results knowsky.com */

$ 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 ~ Value between 16 and generate the final result (3.php)


/* Generate the final result */

$ 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 the target file
$ Result = implode ("", $ rs );
$ Fp = fopen ($ target, "a +") or die ("Open $ target failed ");
Fwrite ($ fp, $ result );
Echo 'write succeed ';

?>


Basically, you have created Random usernames.

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.