Using PHP to generate random user names in batches

Source: Internet
Author: User
Tags count final strlen
Random 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.

$file 1 = "./words.dic";
$file 2 = "./common_pass_mini.dic";
$file 3 = "./sys_month_date.dic";
$rfile = "./5.dic";
$n = 2000;

Extracting dictionaries
$basef = File ($file 1);
$EXTF = File ($file 2);
$EXTF 2 = File ($file 3);
$BF _sum = (count ($basef)-1);
$ef _sum = (count ($EXTF)-1);
$ef 2_sum = (count ($extf 2)-1);

Get random user name
for ($i =0; $i < $n; $i + +)
{
$bn = Crand (0, $BF _sum);
$en = Crand (0, $ef _sum);
$en 2 = Crand (0, $ef 2_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.