Php program used to generate random user names in batches

Source: Internet
Author: User
Php program used to generate random user names in batches

  1. /* Extract random values from dictionary files */

  2. $ File1 = "./Words. dic ";
  3. $ File2 = "./common_pass_mini.dic ";
  4. $ File3 = "./Sys_Month_Date.Dic ";
  5. $ Rfile = "./5.dic ";
  6. $ N = 2000;

  7. // Extract the dictionary

  8. $ Basef = file ($ file1 );
  9. $ Extf = file ($ file2 );
  10. $ Extf2 = file ($ file3 );
  11. $ Bf_sum = (count ($ basef)-1 );
  12. $ Ef_sum = (count ($ extf)-1 );
  13. $ Ef2_sum = (count ($ extf2)-1 );

  14. // Obtain the random user name

  15. For ($ I = 0; $ I <$ n; $ I ++)
  16. {
  17. $ Bn = crand (0, $ bf_sum );
  18. $ En = crand (0, $ ef_sum );
  19. $ En2 = crand (0, $ ef2_sum );
  20. $ Name = $ basef [$ bn]. "_". $ extf [$ en];
  21. $ Name = str_replace ("/r/n", "", $ name );
  22. $ All_name [] = $ name;
  23. }

  24. // Write a file

  25. $ Result = implode ("/r/n", $ all_name );
  26. $ Fp = fopen ($ rfile, "a +") or die ('open $ rfile failed ');
  27. If (fwrite ($ fp, $ result )){
  28. Echo 'write user succeed! ';
  29. } Else {
  30. Echo 'write user failed ';
  31. }

  32. // Generate a random number function

  33. Function crand ($ start, $ end)
  34. {
  35. Return mt_rand ($ start, $ end );
  36. }
  37. ?>

2. Merge the results of the preceding files.

  1. /* Merge all generated results jbxue.com */

  2. $ Result_file = "./result. dic ";

  3. $ Fp = fopen ($ result_file, "a +") or die ("Open $ result_file failed ");

  4. // Merge 1.dic ~ 5. dic

  5. For ($ I = 1; $ I <= 5; $ I ++)
  6. {
  7. $ Cur_file = file_get_contents ($ I. ". dic ");
  8. Fwrite ($ fp, $ cur_file );
  9. }

  10. // Merge 10.dic ~ 11. dic

  11. For ($ I = 10; $ I <= 11; $ I ++)
  12. {
  13. $ Cur_file = file_get_contents ($ I. ". dic ");
  14. Fwrite ($ fp, $ cur_file );
  15. }
  16. Fclose ($ fp );
  17. Echo 'write succeed ';
  18. ?>

3. filter duplicate values and do not belong to 6 ~ Value between 16 and generate final available data

  1. /* Generate the final result */

  2. $ File = "./result. dic ";

  3. $ Target = "./target. dic ";

  4. // Remove duplicate values

  5. $ Files = file ($ file );
  6. $ Files = array_unique ($ files );

  7. // Determine whether the value is greater than 6 bits and less than 16 bits

  8. $ Sum = count ($ files );
  9. For ($ I = 0; $ I <$ sum; $ I ++)
  10. {
  11. If (strlen ($ files [$ I])> = 6 & strlen ($ files [$ I]) <= 16 ){
  12. $ Rs [] = $ files [$ I];
  13. } Else {
  14. Continue;
  15. }
  16. }

  17. // Write the target file

  18. $ Result = implode ("", $ rs );
  19. $ Fp = fopen ($ target, "a +") or die ("Open $ target failed ");
  20. Fwrite ($ fp, $ result );
  21. Echo 'write succeed ';
  22. ?>

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.