Using PHP to generate random user names in batches

Source: Internet
Author: User
Tags count final strlen
Basically handle the hand, the above generated 2.7W a random user name, hehe, to ensure that you use.

Generate a number of 6 ~ 16 user names, mainly text operations, the colleague premise is to have a string package. consists of three programs.

Program one: Responsible for the random extraction of data from the dictionary, write a new file. (1.php)

<?php
* * Extract the random value from the dictionary file.

File1 = "./words.dic";
File2 = "./common_pass_mini.dic";
File3 = "./sys_month_date.dic";
Rfile = "./5.dic";
n = 2000;

Extracting dictionaries
Basef = file (file1);
EXTF = file (file2);
EXTF2 = file (file3);
Bf_sum = (count (Basef)-1);
Ef_sum = (count (EXTF)-1);
Ef2_sum = (count (EXTF2)-1);

Get 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 to 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 ';
}

Generating random number functions
function Crand (start, end)
{
Return Mt_rand (start, end);
}
?>


Program two: Responsible for merging the results of several files generated above. (2.php)

<?php
/* Merge all Build results knowsky.com*/

Result_file = "./result.dic";

fp = fopen (Result_file, "A +") or Die ("Open result_file failed");

Combined 1.dic ~ 5.dic
for (I=1; i<=5; i++)
{
Cur_file = file_get_contents (i.). DiC ");
Fwrite (FP, cur_file);
}

Combined 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 ';

?>


Program three: Responsible for filtering duplicate values and values that are not part of 6~16 and generating final results (3.php)


<?php
/* Generate final result * *

File = "./result.dic";
target = "./target.dic";

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

Determines whether the value is greater than 6 bits or 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 to destination file
result = Implode ("", RS);
FP = fopen (Target, "A +") or Die ("Open target Failed");
Fwrite (FP, result);
Echo ' Write succeed ';

?>


Basically handle the hand, the above generated 2.7W a random user name, hehe, to ensure that you use.



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.