Using PHP to generate random user names in batches
Last Update:2017-02-28
Source: Internet
Author: User
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.