Random.php 838 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class Random{
  3. public static function uuid($whole = false){
  4. $id = strtolower(md5(uniqid(mt_rand(0, (double)microtime() * 1000000), true)));
  5. if($whole){
  6. $uuid =
  7. substr($id, 0, 8)."-".
  8. substr($id, 8, 4)."-".
  9. substr($id, 12, 4)."-".
  10. substr($id, 16, 4)."-".
  11. substr($id, 20, 12)
  12. ;
  13. }
  14. else
  15. $uuid = $id;
  16. return $uuid;
  17. }
  18. public static function num($len = 6){
  19. $nums = array(6, 8, 1, 7, 2, 5, 3, 9, 0, 4);
  20. if($len > 10) $len = 10;
  21. else if($len < 1) $len = 1;
  22. shuffle($nums);
  23. shuffle($nums);
  24. $num = implode("", $nums);
  25. $num = substr($num, 0, $len);
  26. return (string)$num;
  27. }
  28. public static function str(){
  29. $letters = array("d", "m", "q", "n", "t", "l", "s", "i", "b", "k", "u", "e", "h", "y", "x", "r", "w", "a", "p",
  30. "g", "j", "v", "z", "c", "o", "f");
  31. }
  32. }