How to correctly use PHP random number class_php tutorial

Source: Internet
Author: User
How to correctly use the PHP random number class. PHP random number sample code :? PhpclassgetRandstrClass {functiongetCode ($ length32, $ mode0) {switch ($ mode) {case1: $ str1234567890; break; case2: $ strabcde

Sample PHP random number code:

  1. <? Php
  2. Class getRandstrClass {
  3. Function getCode ($ length = 32, $ mode = 0 ){
  4. Switch ($ mode ){
  5. Case '1 ':
  6. $ Str = '000000 ';
  7. Break;
  8. Case '2 ':
  9. $ Str = 'abcdefghijklmnopqrstuvwxy ';
  10. Break;
  11. Case '3 ':
  12. $ Str = 'abcdefghijklmnopqrstuvwxy ';
  13. Break;
  14. Case '4 ':
  15. $ Str = 'abcdefghijklmnopqrstuvwxyza
    Bcdefghijklmnopqrstuvwxyz '; break;
  16. Case '5 ':
  17. $ Str = 'abcdefghijklmnopqrstuvwxyz1234567890 ';
  18. Break;
  19. Case '6 ':
  20. $ Str = 'abcdefghijklmnopqrstuvwxyz1234567890 ';
  21. Break;
  22. Default:
  23. $ Str = 'abcdefghijklmnopqrstuvwxyzabcde
    Fghijklmnopqrstuvwxyz1234567890 ';
  24. Break;
  25. }
  26. $ RandString = '';
  27. $ Len = strlen ($ str)-1;
  28. For ($ I = 0; $ I<$ Length; $ I ++ ){
  29. $ Num = mt_rand (0, $ len );
  30. $ RandString. = $ str [$ num];
  31. }
  32. Return $ randString;
  33. }
  34. }
  35. /* Usage
  36. $ Code = new getRandstrClass ();
  37. $ Length = 4;
  38. $ Mode = 0;
  39. $ Str = $ code->GetCode ($ length, $ mode );
  40. Echo $ str;
  41. $ Code = NULL;
  42. */
  43. ?>

The above code is the specific usage of the PHP random number class.


Why :? Php classgetRandstrClass {functiongetCode ($ length = 32, $ mode = 0) {switch ($ mode) {case '1': $ str = '000000'; break; case '2': $ str = 'ABCDE...

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.