Posted By

Arvi on 12/08/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

bobbym245
Onfire60


Generating random numbers and alphanumerics


 / Published in: PHP
 

Attempt to generate random numbers or random alphanumerics

  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  

You need to login to post a comment.