Generating random numbers and alphanumerics


/ Published in: PHP
Save to your folder(s)

Attempt to generate random numbers or random alphanumerics


Copy this code and paste it in your HTML
  1. //------------------------------------------------------------------------------------------
  2. /*
  3.  * Create numeric token
  4.  */
  5. private function createNumericToken($max_loop=210)
  6. {
  7. $token = null;
  8. for($i=0; $i < $max_loop; $i++)
  9. {
  10. $token .= mt_rand(0, 9);
  11. }
  12.  
  13. return $token;
  14. }
  15.  
  16. //------------------------------------------------------------------------------------------
  17. /*
  18.  * Create alphanumeric token
  19.  */
  20. private function createAlphanumericToken($max_loop=5)
  21. {
  22. $token = null;
  23. for($i=0; $i < $max_loop; $i++)
  24. {
  25. $token .= md5(uniqid());
  26. }
  27.  
  28. return $token;
  29. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.